仿真通过
#include <STC89C5xRC.H>
#include "intrins.h"
#define FOSC 11059200L
#define T1MS (65536-FOSC/12/1000)
#define DATA P2
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P1^2;
sbit SH=P2^0;
sbit DS=P2^1;
sbit ST=P2^2;
sbit led=P0^0;
unsigned int cnt;
void Delay1ms(void) //@11.0592MHz
{
unsigned char data i, j;
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
void TIM0_Isr() interrupt 1
{
TH0=T1MS>>8;
TL0=T1MS;
cnt++;
if(cnt>=500)
{
led=~led;
cnt=0;
}
}
void TIM0_Init()
{
TMOD=0X01;
TH0=T1MS>>8;
TL0=T1MS;
ET0=1;
TR0=1;
}
void LCD_WriteCom(unsigned char com)
{
RS=0;
RW=0;
E=0;
DATA=com;
Delay1ms();
E=1;
}
void LCD_WriteData(unsigned char dat)
{
RS=1;
RW=0;
E=0;
DATA=dat;
Delay1ms();
E=1;
}
void LCD_Init()
{
LCD_WriteCom(0x38);
LCD_WriteCom(0x0C);
LCD_WriteCom(0x06);
LCD_WriteCom(0x01);
}
void LCD_SetPos(unsigned int x,unsigned int y)
{
if(y==0)
LCD_WriteCom(0x80+x);
if(y==1)
LCD_WriteCom(0x80+0x40+x);
}
void LCD_ShowStr(unsigned char *p)
{
while(*p)
{
LCD_WriteData(*p++);
}
}
void HC595_Write(unsigned char c)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((c<<i) & 0x80)
DS=1;
else
DS=0;
Delay1ms();
SH=0;
SH=1;
}
}
void HC595_WriteCom(unsigned char com)
{
HC595_Write(com);
DS=0;
Delay1ms();
ST=0;
ST=1;
}
void HC595_WriteData(unsigned char dat)
{
HC595_Write(dat);
DS=1;
Delay1ms();
ST=0;
ST=1;
}
void HC595_Init()
{
HC595_WriteCom(0x38);
HC595_WriteCom(0x0C);
HC595_WriteCom(0x06);
HC595_WriteCom(0x01);
}
void HC595_SetPos(unsigned int x,unsigned int y)
{
if(y==0)
HC595_WriteCom(0x80+x);
if(y==1)
HC595_WriteCom(0x80+0x40+x);
}
void HC595_ShowStr(unsigned char *p)
{
while(*p)
{
HC595_WriteData(*p++);
}
}
void main()
{
cnt=0;
led=1;
TIM0_Init();
EA=1;
HC595_Init();
HC595_SetPos(0,0);
HC595_ShowStr("Hi,Bona!");
while(1)
{
}
}