和網路上的 LMC-SSC2A16
是同樣的所以可參考同一份PDF
想做這個是以後可用一個簡易的LCD
當做Debug使用
因為沒有ICE ~_~
所以就用變通的方法
最少這樣還能簡易的除錯
還不錯用
/*
LMC - ssc2a16 user atmel 89s52
show addr 1 2 3 4 ~~~ 16
one line 00H 01H 02H 03H 10H
two line 40H 41H 42H 43H 50H
By Brian @Taiwan
*/
#include "AT89X52.H"
#define LCM_En P1_0
#define LCM_Rs P1_1
#define LCM_Rw P1_2
#define LCM_Data_port P2
void sys_init(void); //system initial
void msDelay(unsigned int MaxDelay); //del function
void LCM_Init(void); //lcm initial
//void CheckBusy(void); //lcm chech write ok?
void LCM_Com_Writer(void); //lcm write command
void LCM_Show_Data(unsigned char addr,unsigned char *sd);
unsigned int DelayCNT;
unsigned int TimeCNT;
void main(void)
{
unsigned char SData1[]="Brian @Taiwan";
unsigned char SData2[]="LCD Test OK!";
char i=0;
sys_init();
msDelay(10);
LCM_Init();
msDelay(10);
LCM_Show_Data(0x81,SData1);
LCM_Show_Data(0xC2,SData2);
while(1)
{
// code
}
}
void sys_init(void)
{
//ALL SYSTEM REG SET
IE = 0x82; //USER INTERRUPT TIME0
TMOD = 0x02; //SET TIME 0 MODE
TH0 = 256-200; //SET RELOAD VALUE
TL0 = 256-200; // FAST VALUE
TimeCNT=0;
TR0=1; //time enabled
P1=0x00;
P2=0x00;
}
void Time0_int(void)interrupt 1
{
TimeCNT++;
if(TimeCNT>=10)
{
DelayCNT++;
TimeCNT=0;
}
}
void msDelay(unsigned int MaxDelay)
{
DelayCNT = 0x0000;
while(DelayCNT < MaxDelay) {}
}
void LCM_Init(void)
{
LCM_Data_port = 0x30;
LCM_Com_Writer();
LCM_Data_port = 0x30;
LCM_Com_Writer();
/*
function set 001(dl)(n)(f)xx
(dl=1 data=8bit dl=0 4bit)
(n=1 double line n=0 one line)
(f=0=5*7dot f=1 5*10 dot)
*/
LCM_Data_port = 0x38;
LCM_Com_Writer();
LCM_Data_port = 0x06;//enter mode 01(ld)(s) ld=0 addr++ ld=1 addr-- s=1 addr shift
LCM_Com_Writer();
LCM_Data_port = 0x01;//clear lcm show data
LCM_Com_Writer();
/* lcd on/off 1(d)(c)(b) 1=lcd on 0=lcd off d=lcd c=cursor b=bline */
LCM_Data_port = 0x0C;
LCM_Com_Writer();
}
void LCM_Com_Writer(void)
{
LCM_Rs=0;
LCM_Rw=0;
LCM_En=1;
msDelay(1);
LCM_En=0;
msDelay(1);
}
void LCM_Data_Writer(void)
{
LCM_Rs=1;
LCM_Rw=0;
LCM_En=1;
msDelay(1);
LCM_En=0;
LCM_Rs=0;
msDelay(1);
}
void LCM_Show_Data(unsigned char addr,unsigned char *sd)
{
if(addr!=0)
{
LCM_Data_port = addr;
LCM_Com_Writer();
}
while(*sd!=0)
{
LCM_Data_port = *sd++;
LCM_Data_Writer();
}
}
/*void CheckBusy(void)
{
unsigned char i=0x80;
LCM_Rs=0;
LCM_Rw=1;
LCM_En=1;
while(i&0x80)
{
i=P2;
msDelay(2);
}
LCM_Rs=0;
LCM_Rw=0;
LCM_En=0;
} */
沒有留言:
張貼留言