CFA735-TML-KR1 with PIC18F4520


New member
I have based all of my code on this post:

CFA635 with PIC host #18

I am using MPLAB v.8.91 with the Microchip C18 compiler on a Windows 7 64-bit Pro machine.

I am powering the LCD through H1 +5Vdc & Ground and have pins 1 and 2 connected to the PIC18F4520 Tx (pin 25) and Rx (pin 26) according to the pin-out on page 32 of the CFA735-TML-KR1 datasheet.

I am able to send commands with the 635_WinTest software but have not connected both the external power supply and USB at the same time. I have not cleared J10 on the CFA735-TML-KR1.

When I send the "Hello World" packet listed in the aforementioned thread, the CFA735-TML-KR1 does not display text nor does it respond. I have verified that I am getting the correct CrC code (0xE50E). My code is listed below. Thank you for your assistance.


#include <p18f4520.h>
#include <delays.h>
#include <stdio.h>
#include <stdlib.h>
#include <usart.h>
#include <string.h>
#include <delays.h>

void InitPic(void);
unsigned short get_crc(unsigned char count,unsigned char *ptr);
void send_CRC(void);

// Configuration bits
#pragma config OSC = HS									//High-speed Oscillator
#pragma config FCMEN = OFF								//Fail-Safe Clock monitor disabled
#pragma config IESO = OFF								//Int-Ext. Switch-Over disabled
#pragma config PWRT = OFF								//Power-up Timer disabled
#pragma config BOREN = OFF								//Brown Out Detect disabled
#pragma config WDT = OFF								//Watchdog Timer disabled
#pragma config MCLRE = ON								//Master Clear Enabled
#pragma config STVREN = ON								//Stack full/underflow will cause reset
#pragma config LVP = OFF								//Single-Supply ICSP disabled
#pragma config XINST = OFF								//Extended CPU mode disabled
#pragma config DEBUG = ON								//Debugger Enabled
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
#pragma config CPB = OFF, CPD = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
#pragma config EBTRB = OFF


	unsigned int crc_temp;
	unsigned int crc;
	unsigned long int Combine_CrC;
	unsigned char array_size;
	unsigned char CrC_Msb,CrC_Lsb;
	unsigned char i;

unsigned char data_HW[24] = {0x1F,0x16,0x00,0x00,'H','e','l','l','o',' ','W','o','r','l','d',' ',' ',' ',' ',' ',' ',' ',' ',' '};


void InitPIC(void)                      
  	TRISA = 0x00; // Configure PORT A as output


	TRISCbits.TRISC6 = 0;				//TX1 PIN 31
	TRISCbits.TRISC7 = 1;				//RX1 PIN 32

   				USART_CONT_RX &
   				USART_BRGH_HIGH, 10 ); 	//130 is used for 20MHz Fosc and 9600 baud
   										//10 is used for 20MHz Fosc and 115200 baud
   	//printf((const far rom char *)"\n\rInitPIC\n\r");

unsigned short get_crc(unsigned char count,unsigned char *ptr)
		unsigned short crc; 	//Calculated CRC
		unsigned char i; 		//Loop count, bits in byte
		unsigned char data; 	//Current byte being shifted 
		crc = 0xFFFF; 			// Preset to all 1's, prevent loss of leading zeros 
				data = *ptr++; 
				i = 8; 
					if((crc ^ data) & 0x01) 
							crc >>= 1;
							crc ^= 0x8408; 
					else crc >>= 1; 
					data >>= 1; 
					} while(--i != 0);
			return (~crc);

void send_CRC(void)
    CrC_Lsb = crc;
    CrC_Msb = crc/256;
    putcUSART(CrC_Lsb);   //LSB CRC, 14 or 0x0E
    putcUSART(CrC_Msb);  //MSB CRC, 229 or 0xE5


void main(void) {

	char c[10];
	InitPIC();	//sets up i/o etc
	array_size = 24;

			while (BusyUSART());                     //checks to make sure the USART bus is not busy
			crc = get_crc(array_size,data_HW);
			for (i = 0; i < 25; i++) 
				putcUSART(data_HW[i]);   // alternative method putcUSART(data);
				//putrsUSART((const far rom char *)"\n\rSending Data\n\r");  //These statements are for test purposes and
				//Delay1KTCYx(125);                                                             //are sent to a terminal on my PC to verify data transmission
			PORTAbits.RA0 = 0; 	//Test LED on
		   	while(DataRdyUSART() !=1); //wait for data to be present on bus
			PORTAbits.RA0 = 1;    //Test LED off
			PORTAbits.RA0 = 0;    //Test LED on
			PORTAbits.RA0 = 1;
			PORTAbits.RA0 = 0;

//			//putrsUSART((const far rom char *)"\n\rData Sent\n\r"); //These statements are for test purposes and
//			//printf((const rom far char *)"\n\r%X",CrC_Lsb);             //are sent to a terminal on my PC to verify CrC
//			//printf((const rom far char *)"\n\r%X",CrC_Msb);
//			//printf((const rom far char *)"\n\r%X",crc);



Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
USB LCD Displays - Graphic and Character LCDs with a Keypad