?? test.c
字號(hào):
/***************************************************************/
/******** Program Description : Prepaid Energy Meter Program ***/
/***************** Programmer : Amit Kumar Das *****************/
/*************** Program Date : 26th December 2008 *************/
/*************** Program Time : 08:58 AM ***********************/
/************ Microcontroller : AT89C52 ************************/
/******** Operating Frequency : 12.0MHz ************************/
/***************************************************************/
#include <reg51.h>
#include <string.h>
sbit rs = P2^7; // declare P2.7 as rs pin
sbit en = P2^5; // declare p2.5 as enable pin
sbit rw = P2^6; // declare p2.6 as read/write pin
sbit b = P0^7; // busy flag
sbit X1 = P3^5; // interrupt input for pulse counting
sbit outbit = P3^0; // ouput for relay
void writecmd(unsigned char a); // function to send command to LCD
void writedat(unsigned char b); // function to send data to LCD
void busy(); // function to check LCD is busy or not
void writestr(unsigned char *s); // function to write string on LCD
void MSDelay(unsigned int); // delay function
void writecmd(unsigned char a)
{
busy(); // check for LCD is busy or not
rs = 0; // clear rs pin for command
rw = 0; // clear rw pin to write
P0 = a; // send command character
en = 1; // strob LCD
en = 0;
}
void writedat(unsigned char b)
{
busy(); // check for LCD is busy or not
rs = 1; // set rs pin for data
rw = 0; // clear rw pin to write
P0 = b; // send data character
en = 1; // strob LCD
en = 0;
}
void busy()
{
en = 0; // disable display
P0 = 0xFF; // configur P0 as input
rs = 0; // clear rs pin for command
rw = 1; // set rw pin to read
while(b==1)
{
en=0; // strob LCD till P0.7 is 1
en=1;
}
en=0;
}
void writestr(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i<l;i++)
{
writedat(*s); // write every char one by one
s++;
}
}
void MSDelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void main(void)
{
P0=0x00; // P0 and P2 as output ports
P2=0x00; // LCD controls output
P1=0xFF; // input for card data(currency)
X1=1; // interrupt input for pulse counting
outbit=0x00; // output for relay
writecmd(0x38); // initialize 5X7 matrix LCD
writecmd(0x0E);
writecmd(0x82); // move cursor to first line 2nd pos
writecmd(0x01); // clear memory and home cursor
writestr("Prepaid Energy "); // write message in first line
writecmd(0xC4); // move cursor to second line 4th pos
writestr("Meter ");
MSDelay(500);
here: writecmd(0x01);
writecmd(0x82);
writestr("Please Insert ");
writecmd(0xC7);
writestr("Card ");
if(P1==0x01)
{
writecmd(0x01);
writecmd(0x83);
writestr("Card Found ");
writecmd(0xC3);
writestr("Value = 10 Rs. ");
MSDelay(500);
outbit=0xFF;
TMOD=0x60;
TH1=250;
TL1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 1 Unit ");
writecmd(0xC2);
writestr("BAL = 9 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 2 Units ");
writecmd(0xC2);
writestr("BAL = 8 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 3 Units ");
writecmd(0xC2);
writestr("BAL = 7 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 4 Units ");
writecmd(0xC2);
writestr("BAL = 6 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 5 Units ");
writecmd(0xC2);
writestr("BAL = 5 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 6 Units ");
writecmd(0xC2);
writestr("BAL = 4 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 7 Units ");
writecmd(0xC2);
writestr("BAL = 3 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 8 Units ");
writecmd(0xC2);
writestr("BAL = 2 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 9 Units ");
writecmd(0xC2);
writestr("BAL = 1 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 10 Units ");
writecmd(0xC2);
writestr("BAL = 0 Rs ");
outbit=0x00;
writecmd(0x01);
writecmd(0x80);
writestr("Please Recharge ");
writecmd(0xC6);
writestr("Card ");
}
else if(P1==0x02)
{
writecmd(0x01);
writecmd(0x83);
writestr("Card Found ");
writecmd(0xC3);
writestr("Value = 20 Rs. ");
MSDelay(500);
outbit=0xFF;
TMOD=0x60;
TH1=250;
TL1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 2 Unit ");
writecmd(0xC1);
writestr("BAL = 18 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 4 Units ");
writecmd(0xC1);
writestr("BAL = 16 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 6 Units ");
writecmd(0xC1);
writestr("BAL = 14 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 8 Units ");
writecmd(0xC1);
writestr("BAL = 12 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 10 Units ");
writecmd(0xC1);
writestr("BAL = 10 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 11 Units ");
writecmd(0xC1);
writestr("BAL = 9 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 12 Units ");
writecmd(0xC1);
writestr("BAL = 8 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 13 Units ");
writecmd(0xC1);
writestr("BAL = 7 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 14 Units ");
writecmd(0xC1);
writestr("BAL = 6 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x81);
writestr("Used : 15 Units ");
writecmd(0xC1);
writestr("BAL = 5 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x80);
writestr("Used : 16 Units ");
writecmd(0xC2);
writestr("BAL = 4 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x80);
writestr("Used : 17 Units ");
writecmd(0xC2);
writestr("BAL = 3 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x80);
writestr("Used : 18 Units ");
writecmd(0xC2);
writestr("BAL = 2 Rs ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x80);
writestr("Used : 19 Units ");
writecmd(0xC2);
writestr("BAL = 1 Re ");
TMOD=0x60;
TH1=250;
TR1=1;
while(TF1==0); // wait for timer overflow
TR1=0;
TF1=0;
writecmd(0x01);
writecmd(0x80);
writestr("Used : 20 Units ");
writecmd(0xC2);
writestr("BAL = 0 Rs ");
outbit=0x00;
writecmd(0x01);
writecmd(0x80);
writestr("Please Recharge ");
writecmd(0xC6);
writestr("Card ");
}
else goto here;
while(1); // continuous loop
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -