In this session our kit LCD P0 is for Data and P3. 6 is R/s Register Select and P3. 7 is for E/N Enable pin. You have interface these adc is very easy just copy we code and compile using keil or Ride compiler without no errors. U have to only P89v51rd2 compiler because the spi protocol library function is there in the header file.
#include "p89v51rd2. h" #include "stdio. h" #include "string. h" #define LCD_clear() LCD_command(0x01) /* Clear display LCD */ #define LCD_origin() LCD_command(0x02) /* Set to origin LCD */ #define LCD_row1() LCD_command(0x80) /* Begin at Line 1 */ #define LCD_row2() LCD_command(0xC0) sbit rs = P36; sbit en = P37; sbit cs = P22; void delay (); void display(int name1); void spi (); // <7465> *// void lcd_en () { // rw=0; en = 1; en = 1; en = 1; en = 0; en = 0; } void LCD_delay(unsigned char ms) { unsigned int n; unsigned int i; for (n=0; n { for (i=0; i<1535; i+); /* For 1 ms */ } } void LCD_command(unsigned char command) { rs=0; rs = 0; P0 = command; lcd_en (); LCD_delay(1); } void LCD_init() { LCD_command(0x38); LCD_command(0x06); LCD_command(0x0c); LCD_command(0x01); } void LCD_putc(unsigned char ascii) { rs=1; P0 = ascii; lcd_en (); LCD_delay(2); } void LCD_puts(unsigned char *lcd_string) { while (*lcd_string) { LCD_putc(*lcd_string+); } } void display(int name1) //LCD display routine for digits display { rs = 1; P0 = name1; lcd_en(); LCD_delay(10); } void delay1() { int i =20000; while(i-); } // <7465> *// void spi () { SPCTL = 0X5C; } void main (void) { char c, i; int e=0; LCD_init(); spi (); cs = 0; while(1) { SPDAT = 0XC0; while (SPCFG != 0X80); SPCFG = 0; c = SPDAT; SPDAT = 0XFF; while(SPCFG != 0X80); SPCFG = 0; i = SPDAT; cs = 1; cs = 1; cs = 0; e = c; e = e<<8; e = e | i; e = e<<1; e = e & 0x0fff; LCD_puts("MCP3202 ADC");//display in LCD LCD_command(0xc0); delay1(); { display(e%10000)/1000)+48); //, display(e%1000)/100)+48); //, display(e%100)/10)+48); //, display(e%10)+48); //, } delay1(); LCD_delay(500); LCD_command(0xc5); LCD_command(0x01); printf("%d ", e); }