#include<htc.h>
#include "lcdsub.c"
//#define ss RC0
void spi_init();
unsigned char spi_rx();
void spi_str(unsigned char *s);
void spi_init()
{
SSPSTAT = 0x40;
SSPCON = 0x34;
//SSPCON=0x24;
}
unsigned char spi_rx()
{
unsigned char dat;
//lcd_cmd(0x80);
//lcd_str("receiving");
while(BF==0);
dat=SSPBUF;
//BF=1;
// while(BF==0);
//lcd_cmd(0x80);
//lcd_data('p');
BF=0;
return dat;
}
void spi_str(unsigned char *s)
{
while(*s)
{
delay(65000);
spi_tx(*s++);
}
}
unsigned int p[20];
void main()
{
TRISA5=0;
TRISE0=0;
TRISE1=0;
TRISE2=0;
TRISD=0x00;
TRISC3=1;
TRISC4=1;
//TRISC5=0;
ADCON1=0x07;
TRISC6=0;TRISC7=1;
lcd_init();
spi_init();
lcd_cmd(0x80);
lcd_str(" SPI SAMPLE ");
lcd_cmd(0xc0);
lcd_str(" PROGRAM ");
delay(65500);//delay(65500);
//delay(65500);//delay(65500);
lcd_cmd(0x80);
lcd_str(" ");
lcd_cmd(0xc0);
lcd_str(" ");
lcd_cmd(0x80);
lcd_str("data received ");
lcd_cmd(0xc0);
while(1)
{
unsigned int tem,i;
//lcd_cmd(0x80);
//lcd_str("data received ");
//lcd_cmd(0xc0);
for(i=0;i<20;i++)
//while((tem=spi_rx()))
{
if(tem!='*')
{
tem=spi_rx();
delay(65000);
lcd_data(tem);
delay(65000);
}
}
if(tem=='*')
{
i=100;
//lcd_str("data received ");
//tem=spi_rx();
//delay(65000);
//lcd_data(tem);
//p[i]=tem;
//}while(i<16);
//{
tem='s';
delay(65000);
}
// lcd_cmd(0x80);
//lcd_cmd(0x01);
// lcd_str("data received ");
//delay(65000);
lcd_cmd(0x01);
//lcd_cmd(0xc0);
//lcd_str(p);
//delay(65000);delay(65000);delay(65000);
//}
//delay(65500);delay(65500); delay(65500);delay(65500);
}
}
void lcd_data(unsigned char);
void lcd_cmd(unsigned char);
void lcd_str(char* );
void delay(unsigned int);
void lcd_init();
int count=0;
void lcd_init()
{
lcd_cmd(0x0E);
lcd_cmd(0x80);
lcd_cmd(0x38);
}
void lcd_data(unsigned char lcd_val)
{
if(count==16)
{
lcd_cmd(0xc0);
}
if(count==32)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
count=0;
}
PORTD=lcd_val;
RE2=1;
RE1=0;
RE0=1;
delay(100);
RE0=0;
count++;
}
void lcd_cmd(unsigned char lcd_val)
{
PORTD=lcd_val;
RE2=0;
RE1=0;
RE0=1;
delay(6500);
RE0=0;
}
void lcd_str(char *lcd_str1)
{
while(*lcd_str1)
{
lcd_data(*lcd_str1++);
}
}
void delay(unsigned int del)
{
while(del--);
}
#include "lcdsub.c"
//#define ss RC0
void spi_init();
unsigned char spi_rx();
void spi_str(unsigned char *s);
void spi_init()
{
SSPSTAT = 0x40;
SSPCON = 0x34;
//SSPCON=0x24;
}
unsigned char spi_rx()
{
unsigned char dat;
//lcd_cmd(0x80);
//lcd_str("receiving");
while(BF==0);
dat=SSPBUF;
//BF=1;
// while(BF==0);
//lcd_cmd(0x80);
//lcd_data('p');
BF=0;
return dat;
}
void spi_str(unsigned char *s)
{
while(*s)
{
delay(65000);
spi_tx(*s++);
}
}
unsigned int p[20];
void main()
{
TRISA5=0;
TRISE0=0;
TRISE1=0;
TRISE2=0;
TRISD=0x00;
TRISC3=1;
TRISC4=1;
//TRISC5=0;
ADCON1=0x07;
TRISC6=0;TRISC7=1;
lcd_init();
spi_init();
lcd_cmd(0x80);
lcd_str(" SPI SAMPLE ");
lcd_cmd(0xc0);
lcd_str(" PROGRAM ");
delay(65500);//delay(65500);
//delay(65500);//delay(65500);
lcd_cmd(0x80);
lcd_str(" ");
lcd_cmd(0xc0);
lcd_str(" ");
lcd_cmd(0x80);
lcd_str("data received ");
lcd_cmd(0xc0);
while(1)
{
unsigned int tem,i;
//lcd_cmd(0x80);
//lcd_str("data received ");
//lcd_cmd(0xc0);
for(i=0;i<20;i++)
//while((tem=spi_rx()))
{
if(tem!='*')
{
tem=spi_rx();
delay(65000);
lcd_data(tem);
delay(65000);
}
}
if(tem=='*')
{
i=100;
//lcd_str("data received ");
//tem=spi_rx();
//delay(65000);
//lcd_data(tem);
//p[i]=tem;
//}while(i<16);
//{
tem='s';
delay(65000);
}
// lcd_cmd(0x80);
//lcd_cmd(0x01);
// lcd_str("data received ");
//delay(65000);
lcd_cmd(0x01);
//lcd_cmd(0xc0);
//lcd_str(p);
//delay(65000);delay(65000);delay(65000);
//}
//delay(65500);delay(65500); delay(65500);delay(65500);
}
}
void lcd_data(unsigned char);
void lcd_cmd(unsigned char);
void lcd_str(char* );
void delay(unsigned int);
void lcd_init();
int count=0;
void lcd_init()
{
lcd_cmd(0x0E);
lcd_cmd(0x80);
lcd_cmd(0x38);
}
void lcd_data(unsigned char lcd_val)
{
if(count==16)
{
lcd_cmd(0xc0);
}
if(count==32)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
count=0;
}
PORTD=lcd_val;
RE2=1;
RE1=0;
RE0=1;
delay(100);
RE0=0;
count++;
}
void lcd_cmd(unsigned char lcd_val)
{
PORTD=lcd_val;
RE2=0;
RE1=0;
RE0=1;
delay(6500);
RE0=0;
}
void lcd_str(char *lcd_str1)
{
while(*lcd_str1)
{
lcd_data(*lcd_str1++);
}
}
void delay(unsigned int del)
{
while(del--);
}
No comments:
Post a Comment