温州大学瓯江学院本科毕业设计(论文) 机械工程及自动化专业
}
;
void delaynms(unsigned char n) {
unsigned char i; }
bit BusyTest(void) {
bit result;
RS=0; RW=1; E=1; _nop_(); _nop_(); _nop_(); _nop_(); result=BF; E=0; return result; }
void WriteInstruction (unsigned char dictate) {
while(BusyTest()==1);
for(i=0;i RS=0; RW=0; E=0; _nop_(); _nop_(); P0=dictate; _nop_(); _nop_(); _nop_(); 16 温州大学瓯江学院本科毕业设计(论文) 机械工程及自动化专业 _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0; } void WriteAddress(unsigned char x) { WriteInstruction(x|0x80); } void WriteData(unsigned char y) { while(BusyTest()==1); RS=1; RW=0; E=0; P0=y; _nop_(); _nop_(); _nop_(); _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0; } void LcdInitiate(void) { 17 温州大学瓯江学院本科毕业设计(论文) 机械工程及自动化专业 delaynms(15); WriteInstruction(0x38); delaynms(5); WriteInstruction(0x38); delaynms(5); WriteInstruction(0x38); delaynms(5); WriteInstruction(0x0c); delaynms(5); WriteInstruction(0x06); delaynms(5); WriteInstruction(0x01); delaynms(5); } void display_value(void) { unsigned char i; WriteAddress(0x03); i = 0; while(str[i] != '\\0') { WriteData(str[i]); i++; } } void display_ppm(void) { unsigned char n; WriteAddress(0x0d); n= 0; while(str[n] != '\\0') 18 温州大学瓯江学院本科毕业设计(论文) 机械工程及自动化专业 { WriteData(str0[n]); n++; } } void display1(unsigned char x) { WriteAddress(0x09); WriteData(table[x]); } void display2(unsigned char x) { unsigned char i,j; i=x/10; j=x; WriteAddress(0x0a); WriteData(table[i]); WriteData(table[j]); } unsigned char A_D() { unsigned char i,dat; CS=1; CLK=0; CS=0; DIO=1; CLK=1; CLK=0; DIO=1; CLK=1; 19 温州大学瓯江学院本科毕业设计(论文) 机械工程及自动化专业 CLK=0; DIO=0; CLK=1; CLK=0; DIO=1; CLK=1; for(i=0;i<8;i++) { CLK=1; CLK=0; dat<<=1; dat=dat|DIO; } } void main() { unsigned int AD_val; unsigned char Int,Dec; TMOD=0x01; //使用定时器T0的模式1 EA=1; //开总中断 ET0=1; //定时器T0中断允许 TR0=1; //启动定时器T0 TH0=(65536-500)/256; //定时器T0赋初值,每计数200次(217微秒)发送一次中断请求 TL0=(65536-500)%6; //定时器T0赋初值 keyval=0; //按键值初始化为0,什么也不做 ID=0; while(1) { P1=0xdf; CS=1; return dat; delay1ms(); 20