• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

CFA735-TML-KR1 with PIC18F4520

chris.long

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.

Code:
/*****************************************************

#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

/*******************************************************/
//GLOBAL VARIABLES

	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;
	
/*******************************************************/
//CHARACTER ARRAYS

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

/*******************************************************/
//FUNCTIONS

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

	//USART

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

	OpenUSART( USART_TX_INT_OFF &
   				USART_RX_INT_OFF &
   				USART_ASYNCH_MODE &
   				USART_EIGHT_BIT &
   				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 
		
		while(count--) 
			{
				data = *ptr++; 
				i = 8; 
				
				do{ 
					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(1)
		{
			Delay10KTCYx(255);
			
			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
			}	
			send_CRC();
			
			PORTAbits.RA0 = 0; 	//Test LED on
			//Delay10KTCYx(255);
			
		   	while(DataRdyUSART() !=1); //wait for data to be present on bus
			getsUSART(c,4);
			
			PORTAbits.RA0 = 1;    //Test LED off
			Delay10KTCYx(255);
			PORTAbits.RA0 = 0;    //Test LED on
			Delay10KTCYx(255);
			
			PORTAbits.RA0 = 1;
			Delay10KTCYx(255);
			PORTAbits.RA0 = 0;
			Delay10KTCYx(255);

//			//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);
//			
			Delay10KTCYx(255);

	
			

		}


   
}
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
Top