完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include #include #define uint unsigned int #define uchar unsigned char #define delay4us() {_nop_();_nop_();_nop_();_nop_();} ***it RS = P2^0; ***it RW = P2^1; ***it E = P2^2; ***it CS = P1^0; ***it CLK = P1^1; ***it DIO = P1^2; uchar Display_Buffer[] = "0.00A"; uchar code Line1[] = " Current:DC"; void DelayMS(uint ms) { uchar i; while(ms--) { for(i=0;i<120;i++); } } bit LCD_Busy_Check() { bit result; RS = 0; RW = 1; E = 1; delay4us(); result = (bit)(P0&0x80); E = 0; return result; } void LCD_Write_Command(uchar cmd) { while(LCD_Busy_Check()); RS = 0; RW = 0; E = 0; _nop_(); _nop_(); P0 = cmd; delay4us(); E = 1; delay4us(); E = 0; } void Set_Disp_Pos(uchar pos) { LCD_Write_Command(pos | 0x80); } void LCD_Write_Data(uchar dat) { while(LCD_Busy_Check()); RS = 1; RW = 0; E = 0; P0 = dat; delay4us(); E = 1; delay4us(); E = 0; } void LCD_Initialise() { LCD_Write_Command(0x38); DelayMS(1); LCD_Write_Command(0x0c); DelayMS(1); LCD_Write_Command(0x06); DelayMS(1); LCD_Write_Command(0x01); DelayMS(1); } uchar Get_AD_Result() { uchar i,dat1=0,dat2=0; CS = 0; CLK = 0; DIO = 1; _nop_(); _nop_(); CLK = 1; _nop_(); _nop_(); CLK = 0;DIO = 1; _nop_(); _nop_(); CLK = 1; _nop_(); _nop_(); CLK = 0;DIO = 0; _nop_(); _nop_(); CLK = 1;DIO = 1; _nop_(); _nop_(); CLK = 0;DIO = 1; _nop_(); _nop_(); for(i=0;i<8;i++) { CLK = 1; _nop_(); _nop_(); CLK = 0; _nop_(); _nop_(); dat1 = dat1 << 1 | DIO; } for(i=0;i<8;i++) { dat2 = dat2 | ((uchar)(DIO)< CLK = 1; _nop_(); _nop_(); CLK = 0; _nop_(); _nop_(); } CS = 1; return (dat1 == dat2) ? dat1:0; } void main() { uchar i; uint d; //uint d; LCD_Initialise(); DelayMS(10); while(1) { //d= Get_AD_Result()*500.0/255; //d=(d-128)*30/128; d=Get_AD_Result(); d=(d-2.5)/0.067; d=d*500/255; Display_Buffer[0]=d/100+0x30; Display_Buffer[2]=d/10%10+0x30; Display_Buffer[3]=d%10+0x30; Set_Disp_Pos(0x01); i = 0; while(Line1!=' |