I am starting a project by PIC16f877A and TFT smart lcd (chinese brand). I designed a code to interface PIC with TFT to send data. the protocol of the TFT is designed to send 8 bits at a time, which is prepared in the program. The initial results were good, but there is a little bug. The transferred data have lost bits during transfer, and I could not find an answer for this problem. for example, I am supposed to transfer 0x000290FA but the transferred code became 0x000200FA.
This is the code of the project.
typedef unsigned char BOOLEAN;
typedef unsigned char INT8U;
typedef unsigned short INT16U;
typedef unsigned long INT32U;
BOOLEAN HMT_WriteVPN32(INT32U Addr,INT32U Data);
void main() {
UART1_Init(115200); // Initialize UART module at 115200 bps
Delay_ms(100); // Wait for UART module to stabilize
HMT_WriteVPN32(0x00020000,0x000290FA);
delay_ms (500);
HMT_WriteVPN32(0x00020004,0x0008AD6D);
}
BOOLEAN HMT_WriteVPN32(INT32U Addr,INT32U Data)
{
INT16U Hdata = 0, Ldata = 0;
INT16U AddrH = 0, AddrL =0 ;
INT16U AddrHH = 0, AddrHL = 0, AddrLH = 0, AddrLL = 0;
INT16U HHdata = 0, HLdata = 0, LHdata = 0, LLdata = 0;
if((Addr < 0x00020000) || (Addr > 0x0002FFFF))
{
return (FALSE);
}
AddrH = Addr>>16; // Take high 16 data
AddrL = Addr; // Lower 16 data
AddrHH = AddrH >> 8;
AddrHL = AddrH;
AddrLH = AddrL >> 8;
AddrLL = AddrL;
Hdata = Data >> 16; // Take the 32-bit high byte
Ldata = Data ; // Take the 32-bit low byte
HHdata =Hdata >> 6;
HLdata = Hdata ;
LHdata = Ldata >> 6;
LLdata = Ldata ;
SendHead(); // Send frame header
UART1_Write(0x44); // send command
UART1_Write(AddrHH);
UART1_Write(AddrHL);
UART1_Write(AddrLH);
UART1_Write(AddrLL);
UART1_Write(HHdata);
UART1_Write(HLdata);
UART1_Write(LHdata);
UART1_Write(LLdata);
SendTail(); // Send end of frame
return (TRUE);
}