| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| noyz 
 
 
 Joined: 31 Jan 2009
 Posts: 59
 
 
 
			    
 
 | 
			
				| GLCD - issue - PIC18F8527 |  
				|  Posted: Tue Feb 08, 2011 6:07 pm |   |  
				| 
 |  
				| I was wondering why, from time to time, char disappear from lcd, appear to the next call of draw function. 
 PIC 18F8527
 LCD 240x128 t6963 driver
 
 The board had 8 MHZ clock for PIC but I changed with 20mHz.
 I noticed this then I put back 8Mhz and set delay clock to 8 000 000 and notice the same thing from time to time.
 I think that code jumps over the lcd - busy function from time to time.
 
 By the way with 20 Mhz my pic will calculate a sum faster or no ?
 I am having a issue with someone that if I change the clock the PIC speed is the same, this crystal is used only for timers and I don't believe him.
 
  	  | Code: |  	  | #include <18F8527.h>
 #device *=16
 #device adc=10
 #use delay(clock=20000000,RESTART_WDT)
 #fuses HS, BROWNOUT, BORV27, PUT, STVREN, NOLVP
 
 // HARDWARE CONECTION OF PINS  (LCD-PIC):
 #define  LCD_B0   PIN_H0
 #define  LCD_B1   PIN_H1
 #define  LCD_B2   PIN_H2
 #define  LCD_B3   PIN_H3
 #define  LCD_B4   PIN_H4
 #define  LCD_B5   PIN_H5
 #define  LCD_B6   PIN_H6
 #define  LCD_B7   PIN_H7
 
 #define  LCD_WR   PIN_J2
 #define  LCD_RD   PIN_J1
 #define  LCD_CD   PIN_J0
 #define  LCD_RST  PIN_J4
 #define  red   PIN_C2
 #define  green   PIN_C1
 #define  blue   PIN_G0
 
 const int16 TextHome = 0x0000;
 const int8  TextArea = 0x0028; // how many bytes before a new line
 const int16 GraphicsHome = 0x0C00;
 const int8  GraphicsArea = 0x0028; // how many bytes before a new line
 
 const int8 AutoModeWrite = 0xB0;
 const int8 AutoModeRead  = 0xB1;
 const int8 AutoModeReset = 0xB2;
 
 const int8 LCDModeSet  = 0x80;   // send this OR'd with the following
 const int8 LCDMode_OR  = 0b0000;
 const int8 LCDMode_XOR = 0b0001;
 const int8 LCDMode_AND = 0b0010;
 const int8 LCDMode_TA  = 0b0100; // TEXT ATTRIBUTE mode.
 const int8 LCDMode_RAM = 0b1000; // 1=CG RAM, 0=internal CG ROM
 
 const int8 LCDSetCursorPtr  = 0x21;  // cursor address
 const int8 LCDSetCursorSize = 0xA0;  // 1 line cursor
 
 const int8 LCDDispMode = 0x90;   // send this OR'd with the following
 const int8 LCDDisp_BLK = 0b0001;
 const int8 LCDDisp_CUR = 0b0010;
 const int8 LCDDisp_TXT = 0b0100;
 const int8 LCDDisp_GRH = 0b1000;
 
 // VARIABLES:
 unsigned int n;
 
 int   glcd_ReadByte(void);
 void  glcd_WriteByte(int1 cd, int data);
 void  glcd_WriteByteAuto(int data);
 void  glcd_WriteCmd2(int16 data, int cmd);
 void  glcd_WriteCmd1(int data, int cmd);
 void  glcd_gotoxy(int x, int y, int1 text);
 
 // read lcd port
 lcd_port_read() {
 int lcd_read=0;
 if(input(LCD_B0))    { bit_set(lcd_read,0); }      //0
 if(input(LCD_B1))    { bit_set(lcd_read,1); }      //1
 if(input(LCD_B2))    { bit_set(lcd_read,2); }      //2
 if(input(LCD_B3))    { bit_set(lcd_read,3); }      //3
 if(input(LCD_B4))    { bit_set(lcd_read,4); }      //4
 if(input(LCD_B5))    { bit_set(lcd_read,5); }      //5
 if(input(LCD_B6))    { bit_set(lcd_read,6); }      //6
 if(input(LCD_B7))    { bit_set(lcd_read,7); }      //7
 return lcd_read;
 }
 
 //write to lcd port
 void lcd_port(unsigned int8 lcd) {
 output_low(LCD_B0);
 output_low(LCD_B1);
 output_low(LCD_B2);
 output_low(LCD_B3);
 output_low(LCD_B4);
 output_low(LCD_B5);
 output_low(LCD_B6);
 output_low(LCD_B7);
 //      prevod z desítkové na dvojkovou soustavu
 if(bit_test(lcd,0))    { output_high(LCD_B0); }      //0      HW pripojení LCD
 if(bit_test(lcd,1))    { output_high(LCD_B1); }      //1
 if(bit_test(lcd,2))    { output_high(LCD_B2); }      //2
 if(bit_test(lcd,3))    { output_high(LCD_B3); }      //3
 if(bit_test(lcd,4))    { output_high(LCD_B4); }      //4
 if(bit_test(lcd,5))    { output_high(LCD_B5); }      //5
 if(bit_test(lcd,6))    { output_high(LCD_B6); }      //6
 if(bit_test(lcd,7))    { output_high(LCD_B7); }      //7      (krajní vývod LCD)
 
 delay_us(10);
 }
 
 void glcd_init(void) {
 int16 counter;
 output_high(LCD_WR);
 output_high(LCD_RD);
 output_high(LCD_CD);
 
 delay_ms(10);
 // perform a reset
 output_low(LCD_RST);
 delay_us(2);      // delay for a reset - IF THIS WAIT TIME IS TOO MACH (MORE THAN 10us) LCD NOT WORK (I do not know why..)
 output_high(LCD_RST);
 delay_ms(10);
 
 // Set up the graphics and text areas
 glcd_WriteCmd2(TextHome, 0x40);
 glcd_WriteCmd2(TextArea, 0x41);
 glcd_WriteCmd2(GraphicsHome, 0x42);
 glcd_WriteCmd2(GraphicsArea, 0x43);
 
 // set address to 0
 glcd_WriteCmd2(0x0000, 0x24);
 glcd_WriteCmd2(0x0000, 0x24);
 
 // Clear all RAM of LCD (8k)
 glcd_WriteByte(1, AutoModeWrite);
 for (counter = 0; counter < 0x1fff; counter++)
 {
 glcd_WriteByteAuto(0);    // fill everything with zeros
 }
 glcd_WriteByte(1, AutoModeReset);
 }
 
 void glcd_WriteByte(int1 cd, int data)
 {
 int status = 0, temp = 0;
 output_high(LCD_WR);
 output_high(LCD_RD);
 output_high(LCD_CD);
 
 while (status != 0x03) {  // is LCD busy?
 output_low(LCD_RD);
 temp = lcd_port_read();     // read from lcd port
 output_high(LCD_RD);
 status = temp & 0x03;
 }
 
 if(bit_test(cd,0))  output_high(LCD_CD);
 else                output_low(LCD_CD);
 lcd_port(data);
 output_high(LCD_RD);
 output_low(LCD_WR);
 output_high(LCD_WR);
 }
 
 void glcd_WriteByteAuto(int data)
 {
 int status = 0, temp = 0; // status bits ARE DIFFERENT BITS THAN NORMAL
 output_high(LCD_WR);
 output_high(LCD_RD);
 output_high(LCD_CD);
 
 while (status != 0x08) {  // is LCD busy?
 output_low(LCD_RD);
 temp = lcd_port_read();     // read from lcd port
 output_high(LCD_RD);
 status = temp & 0x08;
 }
 
 output_low(LCD_CD);
 lcd_port(data);
 output_low(LCD_WR);
 output_high(LCD_WR);
 }
 
 void glcd_WriteCmd1(int data, int cmd)
 {
 glcd_WriteByte(0, data);
 glcd_WriteByte(1, cmd);
 }
 
 void glcd_WriteCmd2(int16 data, int cmd)
 {
 glcd_WriteByte(0, data & 0xff);
 glcd_WriteByte(0, data>>8);
 glcd_WriteByte(1, cmd);
 }
 
 int glcd_ReadByte(void)
 {
 int data = 0, status = 0, temp = 0;
 output_high(LCD_WR);
 output_high(LCD_RD);
 output_high(LCD_CD);
 
 #asm nop nop #endasm
 
 while (status != 0x03) {  // is LCD busy?
 output_low(LCD_RD);
 temp = lcd_port_read();     // read from lcd port
 output_high(LCD_RD);
 status = temp & 0x03;
 }
 
 output_low(LCD_CD);
 output_low(LCD_RD);
 /////////////////////////////////////////////////////////
 #asm nop nop #endasm    // THIS PAUSE IS VERY NESSESARY !!!//
 /////////////////////////////////////////////////////////
 data = lcd_port_read();     // read from lcd port
 output_high(LCD_RD);
 
 output_high(LCD_CD);
 return data;        // Return the read data
 }
 
 void glcd_putc(char c) {
 glcd_WriteCmd1(c - 0x20, 0xc0);
 }
 void glcd_delc(char c){
 glcd_WriteCmd2(c - 0x20, 0xc0);
 }
 void glcd_gotoxy(int x, int y, int1 text) { // sets memory location to screen location x, y
 // location 1,1 is upper left corner;  text = 1 (text area), text = 0 (graphics area)
 int16 location, home;
 int line;
 
 if (!text) {
 home = GraphicsHome;
 line = GraphicsArea;
 }
 else {
 home = TextHome;
 line = TextArea;
 }
 
 location = home + (((int16)y - 1) * line) + x - 1;
 glcd_WriteCmd2(location, 0x24);
 }
 
 #use fast_io(D)
 
 void main() {
 
 // setup_adc_ports(ALL_ANALOG);
 //setup_adc(ADC_CLOCK_DIV_8);
 setup_psp(PSP_DISABLED);
 setup_spi(FALSE);
 setup_wdt(WDT_ON);
 setup_timer_0(RTCC_DIV_256|RTCC_8_bit);
 setup_timer_1(T1_DISABLED);
 setup_timer_2(T2_DISABLED,0,1);
 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
 enable_interrupts(INT_RTCC);
 enable_interrupts(INT_AD);
 enable_interrupts(INT_RB);
 enable_interrupts(global);
 
 glcd_init();
 glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
 glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH));
 int i=1;
 int16 td=1500;
 while(1) {
 output_high(red);
 output_high(blue);
 output_low(green);
 glcd_gotoxy(i,1,1);
 glcd_putc("It works :o))");
 
 
 /* glcd_gotoxy(i,1,1);
 glcd_putc("It works :o))");
 i++;
 if (i==30) i=1;
 */glcd_gotoxy(1,3,1);
 glcd_putc("LCD with T6963 controller");
 
 glcd_gotoxy(1,6,1);
 glcd_putc("240x128px @ 20MHz - high speed osc");
 
 glcd_gotoxy(1,7,1);
 glcd_putc("welcomeee");
 
 
 glcd_gotoxy(1,12,1);
 glcd_putc("see what's new at noyz2k@gmail.com");
 glcd_gotoxy(1,14,1);
 glcd_putc("bla bla bla");
 glcd_gotoxy(15,15,1);
 glcd_putc("bla bla bla");
 glcd_gotoxy(20,16,1);
 glcd_putc("some more bla bla bla");
 delay_ms(td);
 glcd_gotoxy(i,1,1);
 glcd_delc("It works :o))");
 output_low(blue);
 delay_ms(td);
 output_high(green);
 output_high(blue);
 output_low(red);
 delay_ms(td);
 output_high(red);
 output_high(green);
 output_low(blue);
 delay_ms(td);
 output_low(blue);
 output_high(green);
 output_low(red);
 delay_ms(td);
 output_low(red);
 output_high(blue);
 output_low(green);
 delay_ms(td);
 output_low(blue);
 output_low(green);
 output_low(red);
 delay_ms(td);
 }
 }
 
 | 
 |  |  
		|  |  
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Feb 08, 2011 9:19 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | enable_interrupts(INT_RTCC); enable_interrupts(INT_AD);
 enable_interrupts(INT_RB);
 enable_interrupts(global);
 
 | 
 Your program has no interrupt service routines.  If an interrupt occurs,
 the program will jump to address 0x0008, but nothing will be there.
 The program behavior will be erratic.
 
 Comment out the enable for global interrupts:
 
  	  | Code: |  	  | // enable_interrupts(global);
 
 | 
 
 Also, disable the Watchdog Timer during initial testing of the program.
 If the Watchdog is enabled, the program may reset when you don't
 expect it.  This can cause problems during debugging of the program.
 For example, this routine could lock-up, and never exit.  Then the
 watchdog would reset the PIC:
 
  	  | Code: |  	  | while (status != 0x03) {  // is LCD busy?
 output_low(LCD_RD);
 temp = lcd_port_read();     // read from lcd port
 output_high(LCD_RD);
 status = temp & 0x03;
 }
 | 
 Change the #fuses setting to NOWDT and comment out this line:
 
  	  | Code: |  	  | // setup_wdt(WDT_ON);
 
 | 
 |  |  
		|  |  
		| noyz 
 
 
 Joined: 31 Jan 2009
 Posts: 59
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Feb 09, 2011 1:39 am |   |  
				| 
 |  
				| I will try to do this tonight and see what happens. Thanks for reply.
 
 
 About the speed of uC - and I mean the power of calculation - what do you think, the quartz speed determines how fast a uC will do a sum, multiply, divide or difference between two numbers or the quartz is just to determine the timers, and has nothing to do with the power of calculation?
 |  |  
		|  |  
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Feb 09, 2011 3:25 am |   |  
				| 
 |  
				| The crystal speed, determines how fast the processor runs. Things like multiplication and division take may thousands of instructions, the time for each instruction, _will_ depend totally on the crystal speed. However the number of instructions will depend on code.
 
 So (for example), one programmer elects to use floating point arithmetic, while another spends extra time, and works out how to do the same job using integer arithmetic. The second programmer runs his code on a chip at 4MHz, while the former runs his on a chip at 20Mhz. However the code is faster on the 4MHz chip. The reason is that typically FP maths is perhaps between five and fifty times slower than integer arithmetic. The change in crystal, only give five times processor speed gain....
 Similarly, things like array accesses are typically many times slower than accessing a fixed variable.
 
 So the crystal determines _everything_ about how fast the processor actually runs, but good programming determines how fast the code will actually 'be'.....
 
 Best Wishes
 |  |  
		|  |  
		| noyz 
 
 
 Joined: 31 Jan 2009
 Posts: 59
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Feb 09, 2011 6:17 pm |   |  
				| 
 |  
				| I find out why is restarting my lcd. I made a function for writing the cause of reset on the screen
 so the result is = MCLR_FROM_RUN but I don't have MCLR from pickit2 activated.
 Even if I remove the pickit2, or put NOMCLR in fuses.. still getting this restart cause. :-??
 |  |  
		|  |  
		| noyz 
 
 
 Joined: 31 Jan 2009
 Posts: 59
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 10, 2011 9:20 am |   |  
				| 
 |  
				| I think that I found out why it resets, I read that someone had the same problem with pic18Fxxxx. Mclr doesn't have to do with the problem so the problem is using int16 instead int32.
 And the PIC -resets.
 Pretty uncool thing, no compiler error, not written in any documentation :-?? or maybe i am wrong.
 
 I'll test it tonight
  |  |  
		|  |  
		| noyz 
 
 
 Joined: 31 Jan 2009
 Posts: 59
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 10, 2011 4:54 pm |   |  
				| 
 |  
				| it doesn't make any difference changing all int16 into int32.. :| |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |