Dr_Doggy
Well-Known Member
trying to get this working on non-uart pin(RC1) for LCD NHD-0216K3Z-NSW-BBW-V3
with RS-232 (TTL) protocol, 8-bit data, 1 Stop bit, no parity, no hand-shaking. BAUD rate is 9600
I am getting results but they are a "bit" or 2 off, I think my problem is with delay time, or maybe inversion issue.
Maybe i need to tweak my clock? or set clock up wrong? Maybe im not factoring in properly the time it takes for all the if checking?
tried lots of small adjustments but just not getting it..
please advise if im being over or under sensitive about these things!
thanks!
bad function:
setup code:
with RS-232 (TTL) protocol, 8-bit data, 1 Stop bit, no parity, no hand-shaking. BAUD rate is 9600
I am getting results but they are a "bit" or 2 off, I think my problem is with delay time, or maybe inversion issue.
Maybe i need to tweak my clock? or set clock up wrong? Maybe im not factoring in properly the time it takes for all the if checking?
tried lots of small adjustments but just not getting it..
please advise if im being over or under sensitive about these things!
thanks!
bad function:
Code:
void sendUart(unsigned char datdat)
{
PORTC |= 0b00000010; // start bit
__delay_us(99);
nextstep:
if (datdat&1){PORTC |= 0b00000010; }else{PORTC &= 0b11111101;} set output
__delay_us(99);
datdat = datdat>>1;
if (cnt<8){cnt++;goto nextstep;} // do 8 times
PORTC &= 0b11111101; // stop bit
__delay_us(99);
}
setup code:
Code:
#include <xc.h>
#define _XTAL_FREQ 8000000
main(){
OSCCONbits.SCS = 0; // Clock source defined by FOSC<2:0> of the Configuration Word
OSCCONbits.IRCF0 = 1; // 8 Mhz pls
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
OSCTUNE= 0b00000000; // no drift
INTE = 1; // interrupt used
while(1){}
}
void interrupt INTERRUPT()
{
if(INTF == 1 & INTE == 1) // on interrupt
{
unsigned char dat = 0xAA; // test byte to send to LCD
unsigned char cnt=0;
sendUart(dat);
delayMS(1000); // long pause
INTF = 0;
}
}
Last edited: