#include <reg52.h> #include <intrins.h> #include <absacc.h> #include <stdio.h> #include <math.h> #include <stdlib.h>
#define uchar unsigned char #define uint unsigned int sfr WDTRST = 0xA6; sbit RW = P1^5; sbit Elcm=P1^4; sbit ad0=P0^7; sbit p03=P0^3; sbit tt=P2^0; sbit t0=P3^4; sbit PINEOC=P1^2; sbit DR=P1^0; sbit MDR=P1^1; #define DataPort P0 #define ADDRPort P2 #define Busy 0x80 #define Work_M 0x38//n=1,f=0 #define Cls 0x01 #define Input_M 0x06//i/d=1 ac++ s=0 screen move=off #define Screen_Off 0x08 #define Disp_M 0x0c//d=1 disp=on c=0 cursor=off #define Ddram_Al1 0x80; #define Ddram_Al2 0xc0;//0x80+0x40 #define Wait1us _nop_(); #define Wait2us {_nop_();_nop_();} #define Wait4us {Wait2us;Wait2us;} #define Wait8us {Wait4us;Wait4us;} #define Wait10us {Wait8us;Wait2us;}
unsigned char com,dat;
// uchar xdata ramadd _at_ 0x0200;
unsigned char xdata h1add _at_ 0xff71; unsigned char xdata h2add _at_ 0xff6f; unsigned char xdata h3add _at_ 0xff8f; unsigned char xdata le1 _at_ 0xff10; unsigned char xdata le2 _at_ 0xff11; unsigned char xdata opp _at_ 0x0088;
unsigned char xdata AD0 _at_ 0xff40; unsigned char xdata AD1 _at_ 0xff42; unsigned char xdata AD2 _at_ 0xff44; unsigned char xdata AD3 _at_ 0xff46; unsigned char xdata AD4 _at_ 0xff48; unsigned char xdata AD5 _at_ 0xff4A; unsigned char xdata AD6 _at_ 0xff4C; unsigned char xdata AD7 _at_ 0xff4E; unsigned char xdata c8251 _at_ 0xff50; unsigned char xdata d8251 _at_ 0xff51;
unsigned char xdata COM8279 _at_ 0xff00; //8279com unsigned char xdata DATA8279 _at_ 0xff01; //8279data
unsigned char xdata le1 _at_ 0xff10; unsigned char xdata le2 _at_ 0xff11; unsigned char com,dat; unsigned char count; uchar FREQ;
uchar temp; uchar temp2; void displcd(void); uchar dispc[2][16]= { ' ','0','O','O','T','P','U','T',' ','P','O','W','E','R',' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','B','m',' ',' ',' ' };
code unsigned char ctab[19]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','<','>','L','O','W'};
void DELAY_1MS(uint i) //延时1毫秒子程序 { uchar j; //定义局部变量j while(i--) //每循环一次,变量减一,为零返回 { for(j=0;j<123;j++); //循环123次 } }
void Delay(uint i) { uint j; for(;i>0;i--) { for(j=1;j>0;j--);} }
void initlcd(void){ RW=0; _nop_(); le1=Work_M;
Delay(50); le1=Screen_Off; Delay(50); le1=Cls; Delay(50); le1=Input_M;
Delay(50); le1=Disp_M;
Delay(50); RW=1; }
void displcd(void){ //LCD1602 uint i; RW=0; _nop_();
le1=Ddram_Al1; Delay(200); for (i=0;i<16;i++) { le2=dispc[0]; Delay(200); } le1=Ddram_Al2; Delay(20); for (i=0;i<16;i++) { le2=dispc[1]; Delay(20); // 写字符 } //le2='0';
// 写字符
RW=1; }
void main(void) { //以下设置中断和定时器; EA=1; PT0=1; ET0=1; IT0=1;IT1=1; EX0=1;EX1=1; TCON=0x08; TMOD=0x21; //定时器0为产生1ms的中断,定时器1为9600b/s的波特率发生器; TH0=-1000/256; TL0=-1000%256; TL1=0xfd; TH1=0xfd; SCON=0x50; PCON=0x80; //开定时器 TR1=1; TR0=1; TI=1; while(1){}
}
void intsvr1(void) interrupt 1 //ADC0809 { uchar temp; uchar A,co; uchar B; uchar C; uchar D; //重新装入定时器0的初值; TH0=-10000/256; TL0=-10000%256; FREQ=FREQ+1; if(FREQ==100) { FREQ=0; temp=AD0; A = temp/1000; B = temp%1000/100; C = temp%1000%100/10; D = temp%1000%100%10; co=A*1000+B*100+C*10+D; dispc[1][1] =ctab[B]; dispc[1][2] =ctab[C]; dispc[1][3] =ctab[D]; displcd(); } }
|