关于单片机的毕业论文 下载本文

临沂大学

4.3系统程序 C程序:

#include \#include \#include \

#define busy 0x80

#define uchar unsigned char #define uint unsigned int

sbit RS=P2^3; sbit RW=P2^4; sbit E=P2^5; sbit KEY1=P2^0; sbit KEY2=P2^1; sbit KEY3=P2^2;

uchar code tab[8]={0x02,0x06,0x04,0x0C,0x08,0x09,0x01,0x03}; uchar temp;

void delay(uchar k) { uint i,j;

for(i=0;i

for(j=0;j<60;j++)

25

临沂大学

{;} } }

void test_1602busy() {

P0=0xFF; E=1; RS=0; RW=1; _nop_(); _nop_(); while(P0&busy) { E=0; _nop_(); E=1; _nop_(); } E=0; }

void write_1602Command(uchar co) {

test_1602busy(); RS=0; RW=0; E=0;

26

临沂大学

_nop_(); P0=co; _nop_(); E=1; _nop_(); E=0; }

void write_1602Data(uchar Data) {

test_1602busy(); P0=Data; RS=1; RW=0; E=1; _nop_(); E=0; }

void init_1602(void) {

write_1602Command(0x38); delay(5);

write_1602Command(0x01); delay(5);

write_1602Command(0x06);

27

临沂大学

delay(5);

write_1602Command(0x0F); delay(5);

write_1602Command(0x0C); }

void DisplayOneChar(uchar X, uchar Y, uchar DData) { Y&=1; X&=15; if(Y)X|=0x40; X|=0x80;

write_1602Command(X); write_1602Data(DData); }

void display_1602(uchar *DData,X,Y) {

uchar ListLength=0; Y&=0x01; X&=0x0F; while(X<16) {

DisplayOneChar(X,Y,DData[ListLength]); ListLength++; X++; } }

28