可调时钟程序

  • 格式:txt
  • 大小:1.89 KB
  • 文档页数:11

#include
#include

// Define P3 pins
#define DATA_BUS P0

sbit RS = P2^0;
sbit RW = P2^1;
sbit E = P2^2;

// Define new types
typedef unsigned char uchar;
typedef unsigned int uint;

// Function Prototypes
void check_busy(void);
void write_command(uchar com);
void write_data(uchar lcddata);
void LCD_init(void);
void string(uchar ad ,uchar *s);
void lcd_test(void);
void delay(uint);

void main(void){
LCD_init();
while(1){
string(0x80,"Have a nice day!");
string(0xC0,"Boys and girls!");
delay(1000);
write_command(0x01);
delay(1000);
}
}

/*******************************************
LCD1602 Driver mapped as IO peripheral
*******************************************/
// Delay
void delay(uint j)
{ uchar i = 60;
for(; j>0; j--)
{ while(--i);
i = 59;
while(--i);
i = 60;
}
}

// Test the Busy bit
void check_busy(void){
do{
DATA_BUS = 0xff;
E = 0;
RS = 0;
RW = 1;
E = 1;
_nop_();
} while(DATA_BUS & 0x80);
E = 0;
}

// Write a command
void write_command(uchar com){
check_busy();
E = 0;
RS = 0;
RW = 0;
DATA_BUS = com;
E = 1;
_nop_();
E = 0;
delay(1);
}

// Write Data
void write_data(uchar lcddata){
check_busy();
E = 0;
RS = 1;
RW = 0;
DATA_BUS = lcddata;
E = 1;
_nop_();
E = 0;
delay(1);
}

// Initialize LCD controller
void LCD_init(void){
write_command(0x38); // 8-bits, 2 lines, 7x5 dots
write_command(0x0C); // no cursor, no blink, enable display
write_command(0x06); // auto-increment on
write_command(0x01); // clear screen
delay(1);
}

// Display a string
void string(uchar ad, uchar *s){
write_command(ad);
while(*s>0){
write_data(*s++);
delay(100);
}
}

下载文档原格式

  / 11
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。