#include <reg51.h>
#include <intrins.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uint buffer1,buffer2;
uchar dis1[17] ={'T','o','t','a','l','M','o','n','e','y','=',' ',' ',' ','.',' ','\0'};
uchar dis2[17] ={'C','u','r','r','e','n','t','M','o','n','e','y','=',' ','.',' ','\0'};
sbit LCD_RS = P1^1;
sbit LCD_EN = P1^0;
sbit QQ=P2^0;
sbit WW=P2^1;
sbit EE=P2^2;
sbit RR=P2^3;
void delay(int ms)
{
int i;
while(ms--)
{
for(i =0; i< 250; i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void lcd_wcmd(uchar cmd)
{
//while(lcd_busy());
LCD_RS =0;
LCD_EN =0;
_nop_();
_nop_();
P0 = cmd;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN =1;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN =0;
}
void lcd_wdat(uchar dat)
{
//while(lcd_busy());
LCD_RS =1;
// LCD_RW =0;
LCD_EN =0;
P0 = dat;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN =1;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN =0;
}
void lcd_pos(uchar pos)
{
lcd_wcmd(pos|0x80);
}
void lcd_init()
{
lcd_wcmd(0x38);
delay(5);
lcd_wcmd(0x38);
delay(5);
lcd_wcmd(0x38);
delay(5);
lcd_wcmd(0x0c);
delay(5);
lcd_wcmd(0x06);
delay(5);
lcd_wcmd(0x01);
delay(5);
}
void shujuchuli()
{
float temp1,temp2;
if(QQ==0)
{
temp1=temp1+1;
temp2=1;
}
if(WW==0)
{
temp1=temp1+0.5;
temp2=0.5;
}
if(EE==0)
{
temp1=temp1+0.1;
temp2=0.1;
}
if(RR==0)
{
temp1=temp1+0.1;
temp2=0.1;
}
buffer1=temp1*10;
dis1[11]=(buffer1%10000)/1000+'0';
dis1[12]=(buffer1%1000)/100+'0';
dis1[13]=(buffer1%100)/10+'0';
dis1[15]=buffer1%10+'0';
buffer2=temp2*100;
dis2[13]=(buffer2%1000)/100+'0';
dis2[15]=(buffer2%100)/10+'0';
}
void xianshi()
{uchar i;
lcd_wcmd(0x06);
lcd_pos(0);
delay(5);
lcd_pos(0);
i = 0;
delay(1);
while(dis1 != '\0')
{
lcd_wdat(dis1);
i++;
delay(1);
}
delay(1);
lcd_pos(0x40);
delay(1);
lcd_pos(0x40);
i = 0;
delay(1);
while(dis2 != '\0')
{
lcd_wdat(dis2);
i++;
delay(1);
}
}
main()
{
lcd_init();
while(1)
{
shujuchuli();
xianshi();
}
}
|