#include <c8051f000.h>
// SFR declarations
#include <stdio.h>
#include <intrins.h>
//------------------------------------------------------------------------------
------
// Global CONSTANTS
//------------------------------------------------------------------------------
------
#define DATABUS P0
sbit LCD_RS=P1^0;
sbit LCD_RW=P1^1;
sbit LCD_E=P1^2;
sbit CS=P1^4;
unsigned int *P_data;
unsigned char code name[8]=
{0x41,0x42,0x43,0x44,0x31,0x32,0x33,0x34};//display "ABCD1234"
//--------------------------------------------------------
void delayxus(unsigned char aa)
{
unsigned char data h;
for(h=0;h <=aa;h++) {_nop_();_nop_();}
}
//........................................
void delay1ms(void)
{
unsigned char data i;
for(i=0;i <=250;i++) { _nop_();_nop_(); }
}
//.......................................
void delay100ms(void)
{
unsigned char data i;
for(i=0;i <=50;i++){delay1ms();}
}
//......................................
void wcode(unsigned char bb) //WRITE CODE TO LCD
{
LCD_RW=0; LCD_RS=0; DATABUS=bb;
LCD_E=0; _nop_();_nop_();LCD_E=1;delayxus(20);LCD_E=0;
delayxus(20);
}
//.......................................
void wdata(unsigned char nn)//WRITE DATA TO LCD
{
LCD_RW=0; LCD_RS=1; DATABUS=nn;
LCD_E=0; _nop_();_nop_();LCD_E=1;delayxus(20);LCD_E=0;
delayxus(20);
}
//------------------------------------------------------------------------------
------
// MAIN Routine
//------------------------------------------------------------------------------
------
void main (void) {
unsigned char k;
unsigned char *P_data;
// disable watchdog timer
WDTCN = 0xde;
WDTCN = 0xad;
// set up Timer3 for auto-reload to generate interrupts at 100ms
intervals
EA = 0;
// enable global
interrupts
// set up Crossbar and GPIO
XBR2 = 0x40;
// Enable crossbar and weak pull-ups
PRT0CF |= 0x00;
// enable P1.6 (LED) as a push-pull output
PRT1CF |= 0xf0;
// enable P1.6 (LED) as a push-pull output
delay100ms(); delay100ms(); delay100ms(); delay100ms();
DATABUS=0xff; //SP=0x60;
LCD_E=0; LCD_RW=0; LCD_RS=0;
// EA=0;
wcode(0x30); // 显示模式设置(不检测忙信
号)
delay1ms(); delay1ms();delay1ms();delay1ms();delay1ms();
wcode(0x30); // 显示模式设置(不检测忙信
号)
delay1ms(); delay1ms();delay1ms();delay1ms();delay1ms();
wcode(0x30); // 显示模式设置(不检测忙信
号)
delay1ms(); delay1ms();delay1ms();delay1ms();delay1ms();
wcode(0x30); // 显示模式设置(以后均检测
忙信号)
wcode(0x08); // 显示关闭
wcode(0x01); // 显示清屏
wcode(0x06); // 显示光标移动设置
wcode(0x0c); // 显示开及光标设置
while(1){
P_data=name;
wcode(0x02);delay1ms();//RETURN HOME
wcode(0x01);delay1ms();delay1ms();
for(k=0;k <8;k++) {wdata(*P_data);delayxus(50);P_data++;}
}
}