- Sun Jun 26, 2005 7:19 pm
#5827
I purchased a SerLCD a while back (it is definitely a 1.1 despite having v2.0 silkscreened on it), and I have finally gotten around to starting the project that will actually use it.
I'm writing my code in C, as it will get large, once it is completed, and it is a nicer environment for me to work in.
So far, my test involves sampling the A/D converter every 5 seconds, and writing the output to the LCD as hex.
the code loop looks like this:
The problem is that with the above code, I only ever see a single character displayed on the screen (if the A/D converter is reading 0x34) I get '3'. Now If I remove the screen-clear in the loop, it displays everything correctly (but of course does not reset the display) like 34,0,34,0,.... I can also add a set of 'cursor-forwards,cursor-back' commands inside sendHexByte(between sending the 1st and 2nd character), and everything will display correctly with the above code (alernating 34 and 0).
I am using a 16F88 with the 8MHz internal clock. I have looked over the assembly code, and the copiler hasn't done anything screwy. I don't have a logic-analyzer handy, but I think I can see both bytes being sent (as opposed to the single '0' I use as a reference)
This is my first foray into PIC programming, and my first attempt at using the SerLCD, but I'm getting kinda frustrated, and I can't seem to figure out what is wrong.
In case it is useful, here is the sendHexByte code:
I'm writing my code in C, as it will get large, once it is completed, and it is a nicer environment for me to work in.
So far, my test involves sampling the A/D converter every 5 seconds, and writing the output to the LCD as hex.
the code loop looks like this:
Code: Select all
The interrupt routine takes care of setting 'flags', and sendChar just waites for TXIF, and loads the value into TXREG. The led istuff is just temporary for visualization (led attached to RA2). sendHexByte converts the value into a hex representation (00-FF) and calls sendChar twice. sendChar(0xFE);
sendChar(0x01);
while(1)
{
set_bit(adcon0, GO_DONE); //start A/D
while(! test_bit(flags, SAMPLEREADY) && ! test_bit(flags, ADREADY))
;
sendChar(0xFE);
sendChar(0x01);
if(led_on) {
clear_bit(porta, 2);
led_on=0;
sendChar('0');
} else {
set_bit(porta, 2);
led_on=1;
sendHexByte(adresh);
}
flags=0;
}
The problem is that with the above code, I only ever see a single character displayed on the screen (if the A/D converter is reading 0x34) I get '3'. Now If I remove the screen-clear in the loop, it displays everything correctly (but of course does not reset the display) like 34,0,34,0,.... I can also add a set of 'cursor-forwards,cursor-back' commands inside sendHexByte(between sending the 1st and 2nd character), and everything will display correctly with the above code (alernating 34 and 0).
I am using a 16F88 with the 8MHz internal clock. I have looked over the assembly code, and the copiler hasn't done anything screwy. I don't have a logic-analyzer handy, but I think I can see both bytes being sent (as opposed to the single '0' I use as a reference)
This is my first foray into PIC programming, and my first attempt at using the SerLCD, but I'm getting kinda frustrated, and I can't seem to figure out what is wrong.
In case it is useful, here is the sendHexByte code:
Code: Select all
Any ideas what might be wrong?void sendHexByte(char n)
{
char h;
h=(n>>4)&0xF;
n=n&0xF;
if( h>=10 )
sendChar((h-10)+'A');
else
sendChar(h+'0');
// sendChar(0xFE);
// sendChar(0x14);
// sendChar(0xFE);
// sendChar(0x10);
if( n>=10 )
sendChar((n-10)+'A');
else
sendChar(n+'0');
}