markas
Guest
|
|
« on: March 17, 2010, 12:28:35 AM » |
|
#include<reg51.h> 2 unsigned int patt[]={1,2,4,8}; 3 4 sbit E=P3^6; 5 sbit RS=P3^7; 6 7 sbit coin1=P3^0; 8 sbit coin5=P3^1; 9 sbit coin10=P3^2; 10 11 12 int count=0; 13 14 int count1=0; 15 int count5=0; 16 int count10=0; 17 char status=1; 18 19 int xx,cc; 20 void delay(unsigned int count) 21 { 22 for( count = count ; count >0 ; count--); 23 } 24 25 26 void clock (void) 27 { 28 E=1; 29 delay(200); 30 E=0; 31 delay(200); 32 } 33 34 void write (unsigned char a) 35 { 36 RS=1; 37 P2=a; 38 clock(); 39 RS=0; 40 } 41 42 void clr(void) 43 { 44 45 RS=0; 46 P2=0x01; 47 clock(); 48 49 } 50 51 void inilcd(void) 52 { 53 54 delay(20000); 55 56 RS=0; 57 P2=0x38; 58 clock(); 59 60 clr(); 61 62 P2=0x0d; 63 clock(); 64 65 P2=0x06; 66 clock(); 67 } 68 69 70 void showcointolcd(void) 71 { 72 73 P2=0x80; 74 clock(); 75 write('a'); 76 write('l'); 77 write('l'); 78 write('='); 79 xx=count10*10+(count5*5)+count1; 80 81 write(((xx/1000))+0x30); 82 write(((xx%1000)/100)+0x30); 83 write(((xx%100)/10)+0x30); 84 write(((xx%10))+0x30); 85 write(','); 86 87 xx=count1; 88 write('c'); 89 write('o'); 90 write('i'); 91 write('n'); 92 write(' '); 93 write('1'); 94 write('B'); 95 write('='); 96 write(((xx/100))+0x30); 97 write(((xx%100)/10)+0x30); 98 write(((xx%10))+0x30); 99 100 101 102 P2=0xc0; 103 clock(); 104 xx=count5; 105 write('c'); 106 write('o'); 107 write('i'); 108 write('n'); 109 write(' '); 110 write('5'); 111 write('B'); 112 write('='); 113 write(((xx/100))+0x30); 114 write(((xx%100)/10)+0x30); 115 write(((xx%10))+0x30); 116 117 118 write(','); 119 xx=count10; 120 write('1'); 121 write('0'); 122 write('B'); 123 write('='); 124 write(((xx/100))+0x30); 125 write(((xx%100)/10)+0x30); 126 write(((xx%10))+0x30); 127 128 129 130 } 131 132 133 134 void main(void) 135 { 136 137 inilcd(); 138 139 showcointolcd(); 140 141 st: 142 143 144 P0=patt[count]; 145 count++; 146 if(count>3){count=0;} 147 147cc=0; 148 while(cc<2000) 149 { 150 cc++; 151 if(coin1==0) 152 { count1++; 153 delay(2000); 154 while(coin1==0); 155 showcointolcd(); 156 } 157 else 158 if(coin5==0) 159 { 160 count5++; 161 delay(2000); 162 while(coin5==0); 163 showcointolcd(); 164 } 165 else 166 if(coin10==0) 167 { 168 count10++; 169 delay(2000); 170 while(coin10==0); 171 showcointolcd(); 172 } 173 174 } 175 176 177 178 goto st; 179 180 } 181
|