kvjoshipura
Newbie level 2
- Joined
- Feb 17, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 283
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 SDA1 EQU P3.4 ;SDA=PIN5 SCL1 EQU P3.3 ;SCL=PIN6 WTCMD EQU 10100000B ;WRITE DATA COMMAND Note 3 RDCMD EQU 10100001B ;READ DATA COMMAND Note 3 RED EQU P3.7 GREEN EQU P1.0 KEYS EQU P1 ROW1 EQU P1.1 ROW2 EQU P1.2 ROW3 EQU P1.3 ROW4 EQU P1.4 COL1 EQU P1.7 COL2 EQU P1.6 COL3 EQU P1.5 DSEG ; This is internal data memory ORG 20H ; Bit adressable memory KEY: DS 1 N0: DS 1 N1: DS 1 N2: DS 1 N3: DS 1 N4: DS 1 N5: DS 1 COUNT: DS 1 PASS0: DS 1 PASS1: DS 1 PASS2: DS 1 CHANGE: DS 1 CSEG ; Code begins here ; ---------==========----------==========---------=========--------- ; Main routine. Program execution starts here. 8889 ; ---------==========----------==========---------=========--------- ORG 00H ; Reset MOV SP,#60H CLR RED CLR GREEN CALL DELAY CALL DELAY SETB RED SETB GREEN MOV N1,#01H MOV N2,#0FFH MOV N3,#0FFH MOV N4,#0FFH MOV N5,#0FFH MOV R3,#01H ; MOV N2,#23H ; MOV N4,#45H ; CALL SAX KEYBOARD: MOV KEY,#00H SETB COL1 SETB COL2 SETB COL3 K11: CLR ROW1 CLR ROW2 CLR ROW3 CLR ROW4 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,K11 ;check till all keys released K2: ACALL DEALAY ;call 20 msec delay MOV A,KEYS ;see if any key is pressed ANL A,#11100000B ;mask unused bits CJNE A,#11100000B,OVER ;key pressed, await closure SJMP K2 OVER: ACALL DEALAY MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,OVER1 SJMP K2 OVER1: MOV A,KEYS ORL A,#11111110B MOV KEYS,A CLR ROW1 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_1 MOV A,KEYS ORL A,#11111110B MOV KEYS,A CLR ROW2 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_2 MOV A,KEYS ORL A,#11111110B MOV KEYS,A CLR ROW3 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_3 MOV A,KEYS ORL A,#11111110B MOV KEYS,A CLR ROW4 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_4 LJMP K2 ROW_1: RLC A JC MAT1 MOV KEY,#01H AJMP K1 MAT1: RLC A JC MAT2 MOV KEY,#02H AJMP K1 MAT2: RLC A JC K1 MOV KEY,#03H AJMP K1 ROW_2: RLC A JC MAT3 MOV KEY,#04H AJMP K1 MAT3: RLC A JC MAT4 MOV KEY,#05H AJMP K1 MAT4: RLC A JC K1 MOV KEY,#06H AJMP K1 ROW_3: RLC A JC MAT5 MOV KEY,#07H AJMP K1 MAT5: RLC A JC MAT6 MOV KEY,#08H AJMP K1 MAT6: RLC A JC K1 MOV KEY,#09H AJMP K1 ROW_4: RLC A JC MAT7 MOV KEY,#0AH AJMP K1 MAT7: RLC A JC MAT8 MOV KEY,#00H ;for 0 AJMP K1 MAT8: RLC A JC K1 MOV KEY,#0FH K1: CLR RED CALL DELAY CALL DELAY SETB RED MOV A,KEY CJNE A,#0FH,G0 CJNE R3,#07H,G0 AJMP G8 G0: CJNE R3,#01H,G11 INC R3 MOV N0,KEY AJMP KEYBOARD G11: CJNE R3,#02H,G1 INC R3 MOV N1,KEY AJMP KEYBOARD G1: CJNE R3,#03H,G2 INC R3 MOV N2,KEY AJMP KEYBOARD G2: CJNE R3,#04H,G3 INC R3 MOV N3,KEY AJMP KEYBOARD G3: CJNE R3,#05H,G4 INC R3 MOV N4,KEY AJMP KEYBOARD G4: CJNE R3,#06H,G5 INC R3 MOV N5,KEY G5: AJMP KEYBOARD G8: MOV A,N2 SWAP A ORL A,N3 MOV N2,A ;HIGHER DIGITSS IN N2 MOV A,N4 SWAP A ORL A,N5 MOV N3,A ;LOWER DISITS IN N3 MOV A,N0 CJNE A,#01H,STR_AMT MOV N1,#00H MOV R1,#N1 ;store COUNT MOV R4,#20H ;Starting Address IN EEPROM MOV R6,#3 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY CALL DELAY AJMP CHK_DATA BV1S: AJMP BV1 STR_AMT: CJNE A,#02H,BV1S MOV N1,#01H MOV R1,#N1 ;store COUNT MOV R4,#20H ;Starting Address IN EEPROM MOV R6,#3 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY CALL DELAY ; ---------==========----------==========---------=========--------- ;CHECK WITH DATA STORED IN MEMORY ; ---------==========----------==========---------=========--------- CHK_DATA: MOV R1,#PASS0 ;GET DATA IN BYTES(RAM) MOV R4,#20H ;DATA ADDRESS IN EEPROM MOV R6,#3 ;NUMBER OF BYTES CALL READ_EEPROM MOV A,N1 CJNE A,PASS0, BV1 MOV A,N2 CJNE A,PASS1,BV1 MOV A,N3 CJNE A,PASS2,BV1 CLR GREEN CALL DELAY1 CALL DELAY1 SETB GREEN CALL DELAY1 CALL DELAY1 CLR GREEN CALL DELAY1 CALL DELAY1 SETB GREEN MOV R3,#01H MOV N0,#0FFH MOV N1,#0FFH MOV N2,#0FFH MOV N3,#0FFH MOV N4,#0FFH MOV N5,#0FFH AJMP KEYBOARD BV1: CLR RED CALL DELAY1 CALL DELAY1 SETB RED CALL DELAY1 CALL DELAY1 CLR RED CALL DELAY1 CALL DELAY1 SETB RED MOV R3,#01H MOV N0,#0FFH MOV N1,#0FFH MOV N2,#0FFH MOV N3,#0FFH MOV N4,#0FFH MOV N5,#0FFH AJMP KEYBOARD ;(((((((((((((((((((((((((((((((( DEALAY: MOV R1,#50 REPP2: NOP DJNZ R1,REPP2 RET ;(((((((((((((((((((((((((((((((( ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; READ DATA FROM EEPROM ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% READ_EEPROM: MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS CALL OUTS ;SEND IT MOV A,R4 ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT MOV A,#RDCMD ;LOAD READ COMMAND CALL OUTS ;SEND IT BRDLP: CALL IN ;READ DATA MOV @R1,a ;STORE DATA INC R1 ;INCREMENT DATA POINTER DJNZ R6,AKLP ;DECREMENT LOOP COUNTER CALL STOP ;IF DONE, ISSUE STOP CONDITION RET ;DONE, EXIT ROUTINE AKLP: CLR SDA1 ;NOT DONE, ISSUE ACK SETB SCL1 NOP ;NOTE 1 NOP NOP NOP ;NOTE 2 NOP CLR SCL1 JMP BRDLP ;CONTINUE WITH READS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; STORE DATA IN EEPROM ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STORE_EEPROM: MOV A,#WTCMD ;LOAD WRITE COMMAND CALL OUTS ;SEND IT MOV A,R4 ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT BTLP: MOV A,@R1 ;GET DATA CALL OUT ;SEND IT INC R1 ;INCREMENT DATA POINTER DJNZ R6,BTLP ;LOOP TILL DONE CALL STOP ;SEND STOP CONDITION RET ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;*********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR ; to the EEPROM and includes START condition. Refer to the data sheets ; for discussion of START and STOP conditions. ;*********************************************************************** OUTS: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT SETB SDA1 ;INSURE DATA IS HI SETB SCL1 ;INSURE CLOCK IS HI NOP ;NOTE 1 NOP NOP CLR SDA1 ;START CONDITION -- DATA = 0 NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK = 0 OTSLP: RLC A ;SHIFT BIT JNC BITLS SETB SDA1 ;DATA = 1 JMP OTSL1 ;CONTINUE BITLS: CLR SDA1 ;DATA = 0 OTSL1: SETB SCL1 ;CLOCK HI NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK LOW DJNZ R2,OTSLP ;DECREMENT COUNTER SETB SDA1 ;TURN PIN INTO INPUT NOP ;NOTE 1 SETB SCL1 ;CLOCK ACK NOP ;NOTE 1 NOP NOP CLR SCL1 RET ;********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM ; without sending a START condition. ;********************************************************************** OUT: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT OTLP: RLC A ;SHIFT BIT JNC BITL SETB SDA1 ;DATA = 1 JMP OTL1 ;CONTINUE BITL: CLR SDA1 ;DATA = 0 OTL1: SETB SCL1 ;CLOCK HI NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK LOW DJNZ R2,OTLP ;DECREMENT COUNTER SETB SDA1 ;TURN PIN INTO INPUT NOP ;NOTE 1 SETB SCL1 ;CLOCK ACK NOP ;NOTE 1 NOP NOP CLR SCL1 RET STOP: CLR SDA1 ;STOP CONDITION SET DATA LOW NOP ;NOTE 1 NOP NOP SETB SCL1 ;SET CLOCK HI NOP ;NOTE 1 NOP NOP SETB SDA1 ;SET DATA HIGH RET ;******************************************************************* ; THIS ROUTINE READS A BYTE OF DATA FROM EEPROM ; From EEPROM current address pointer. ; Returns the data byte in R1 ;******************************************************************* CREAD: MOV A,#RDCMD ;LOAD READ COMMAND CALL OUTS ;SEND IT CALL IN ;READ DATA MOV R1,A ;STORE DATA CALL STOP ;SEND STOP CONDITION RET ;********************************************************************** ; THIS ROUTINE READS IN A BYTE FROM THE EEPROM ; and stores it in the accumulator ;********************************************************************** IN: MOV R2,#8 ;LOOP COUNT SETB SDA1 ;SET DATA BIT HIGH FOR INPUT INLP: CLR SCL1 ;CLOCK LOW NOP ;NOTE 1 NOP NOP NOP SETB SCL1 ;CLOCK HIGH CLR C ;CLEAR CARRY JNB SDA1,INL1 ;JUMP IF DATA = 0 CPL C ;SET CARRY IF DATA = 1 INL1: RLC A ;ROTATE DATA INTO ACCUMULATOR DJNZ R2,INLP ;DECREMENT COUNTER CLR SCL1 ;CLOCK LOW RET ;********************************************************************* ; This routine test for WRITE DONE condition ; by testing for an ACK. ; This routine can be run as soon as a STOP condition ; has been generated after the last data byte has been sent ; to the EEPROM. The routine loops until an ACK is received from ; the EEPROM. No ACK will be received until the EEPROM is done with ; the write operation. ;********************************************************************* ACKTST: MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT CLR SDA1 ;START CONDITION -- DATA = 0 NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK = 0 AKTLP: RLC A ;SHIFT BIT JNC AKTLS SETB SDA1 ;DATA = 1 JMP AKTL1 ;CONTINUE AKTLS: CLR SDA1 ;DATA = 0 AKTL1: SETB SCL1 ;CLOCK HI NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK LOW DJNZ R2,AKTLP ;DECREMENT COUNTER SETB SDA1 ;TURN PIN INTO INPUT NOP ;NOTE 1 SETB SCL1 ;CLOCK ACK NOP ;NOTE 1 NOP NOP JNB SDA1,EXIT ;EXIT IF ACK (WRITE DONE) JMP ACKTST ;START OVER EXIT: CLR SCL1 ;CLOCK LOW CLR SDA1 ;DATA LOW NOP ;NOTE 1 NOP NOP SETB SCL1 ;CLOCK HIGH NOP NOP SETB SDA1 ;STOP CONDITION RET ;********************************************************************* DELAY: MOV R0,#0FFH INLOP: MOV R1,#0FFH DJNZ R1,$ DJNZ R0,INLOP RET DELAY1: MOV R0,#0FFH INLOP1: MOV R1,#0FFH DJNZ R1,$ DJNZ R0,INLOP1 RET END (13.)PRE-PAID ENERGY METER PROGRAMMING:- RB0 EQU 000H ; Select Register Bank 0 RB1 EQU 008H ; Select Register Bank 1 ...poke to PSW to use ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; PORT DECLERATION ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SDA1 EQU P2.1 ;SDA=PIN5 SCL1 EQU P2.0 ;SCL=PIN6 WTCMD EQU 10100110B ;WRITE DATA COMMAND Note 3 RDCMD EQU 10100111B ;READ DATA COMMAND Note 3 WTCMD1 EQU 10100000B ;WRITE DATA COMMAND Note 3 RDCMD1 EQU 10100001B ;READ DATA COMMAND Note 3 RELAY EQU P2.7 BUZZER EQU P2.4 ; ***LCD CONTROL*** LCD_RS EQU P0.0 ;LCD REGISTER SELECT LINE LCD_E EQU P0.1 ;LCD ENABLE LINE LCD_DB4 EQU P0.2 ;PORT 1 IS USED FOR DATA LCD_DB5 EQU P0.3 ;USED FOR DATA LCD_DB6 EQU P0.4 ;FOR DATA LCD_DB7 EQU P0.5 ;FOR DATA ; ***CURSOR CONTROL INSTRUCTIONS*** OFFCUR EQU 0CH BLINKCUR EQU 0DH ; ***DISPLAY CONTROL INSTRUCTIONS*** CLRDSP EQU 01H ONDSP EQU 0CH ; ***SYSTEM INSTRUCTIONS*** CONFIG EQU 28H ; 4-BIT DATA,2 LINES,5X7 MATRIX LCD ENTRYMODE EQU 6 ; INCREMENT CURSOR DON'T SHIFT DISPLAY DSEG ; This is internal data memory ORG 20H ; Bit adressable memory FLAGS1: DS 1 BCDCARRY BIT FLAGS1.0 CARRY BIT FLAGS1.1 TBIT BIT FLAGS1.2 TBIT1 BIT FLAGS1.3 READING: DS 2 AMOUNT: DS 3 COUNTER: DS 2 TEMP: DS 1 PRICE: DS 2 BALANCE: DS 1 BUZZ_COUNT: DS 1 READ_BYTE: DS 3 F1: DS 1 F2: DS 1 F3: DS 1 STACK: DS 1 CSEG ; Code begins here ; ---------==========----------==========---------=========--------- ; Main routine. Program execution starts here. ; ---------==========----------==========---------=========--------- ORG 00H ; Reset AJMP MAIN ORG 0003H PUSH PSW PUSH ACC MOV PSW,#RB1 ; Select register bank 0 CALL INC_COUNTER POP ACC POP PSW RETI ; ---------==========----------==========---------=========--------- MAIN: MOV SP,#50H MOV PSW,#RB0 ; Select register bank 0 MOV IE,#10000001B CALL RESETLCD4 CALL TITLE1 CLR BUZZER SETB RELAY CLR TBIT1 MOV BUZZ_COUNT,#00H MOV READ_BYTE,#0FFH CALL READ_COUNTER MOV A,COUNTER CJNE A,#0FFH,BYPASS CALL RESET_READING CALL RESET_AMT CALL RESET_COUNTER CALL RESET_PRICE CALL RESET_BALANCE ;RELAY ON/OFF BYTE ; CALL STORE_UNIT_PRICE ; CALL AMT_RECHARGE CALL SYSTEM_RESET CALL DELAYYS BYPASS: CALL READ_COUNTER CALL READ_PRICE CALL READ_BALANCE MAINS: CALL TITLE1 CALL DELAYY MOV A,BALANCE CJNE A,#00H,FG1 CLR RELAY CALL RECHAGRE CALL DELAYY SETB BUZZER AJMP MAINS FG1: SETB RELAY MOV A,BUZZ_COUNT ;CHK TO SWITCH OFF THE BUZZER CJNE A,#00H,AZX1 CLR BUZZER AJMP AZX2 AZX1: DEC BUZZ_COUNT AZX2: MOV R1,#READING ;GET DATA IN BYTES(RAM) MOV R4,#05H ;DATA ADDRESS IN EEPROM MOV R6,#2 ;NUMBER OF BYTES CALL READ_EEPROM CALL DISP_READING MOV TEMP,READING CALL SEP_DISP MOV TEMP,READING+1 CALL SEP_DISP CALL DELAYY MOV R1,#AMOUNT ;GET DATA IN BYTES(RAM) MOV R4,#0AH ;DATA ADDRESS IN EEPROM MOV R6,#3 ;NUMBER OF BYTES CALL READ_EEPROM CALL AMT_READING MOV TEMP,AMOUNT CALL SEP_DISP MOV TEMP,AMOUNT+1 CALL SEP_DISP MOV R4,#'.' CALL WRLCDDATA CALL MDELAY MOV TEMP,AMOUNT+2 CALL SEP_DISP CALL DELAYY MOV R1,#COUNTER ;GET DATA IN BYTES(RAM) MOV R4,#0EH ;DATA ADDRESS IN EEPROM MOV R6,#2 ;NUMBER OF BYTES CALL READ_EEPROM CALL COUNT_READING MOV TEMP,COUNTER CALL SEP_DISP MOV TEMP,COUNTER+1 CALL SEP_DISP CALL DELAYY MOV R1,#PRICE ;GET DATA IN BYTES(RAM) MOV R4,#10H ;DATA ADDRESS IN EEPROM MOV R6,#2 ;NUMBER OF BYTES CALL READ_EEPROM CALL READ_PRICE CALL UNIT_PRICE MOV A,PRICE ADD A,#30h MOV R4,A CALL WRLCDDATA CALL MDELAY MOV R4,#'.' CALL WRLCDDATA CALL MDELAY MOV TEMP,PRICE+1 CALL SEP_DISP CALL DELAYY AJMP MAINS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 ; INCREMENT COUNTER BY 1 ; IF COUNT=3200 THEN INCREMENT READING ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 INC_COUNTER: MOV A,COUNTER+1 ADD A,#01 DA A MOV COUNTER+1,A JNC DCV2 MOV A,COUNTER ADD A,#01 DA A MOV COUNTER,A CJNE A,#32h,DCV2 MOV COUNTER,#00H MOV COUNTER+1,#00H MOV R1,#COUNTER ;store COUNT MOV R4,#0EH ;Starting Address IN EEPROM MOV R6,#2 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY AJMP DVB1 DCV2: MOV R1,#COUNTER ;store COUNT MOV R4,#0EH ;Starting Address IN EEPROM MOV R6,#2 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY RET DVB1: MOV A,READING+1 ;INCREMENT READING BY 1 ADD A,#01 DA A MOV READING+1,A JNC DCS1 MOV A,READING ADD A,#01 DA A MOV READING,A DCS1: MOV R1,#READING ;store READING MOV R4,#05H ;Starting Address IN EEPROM MOV R6,#2 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY MOV A,AMOUNT+2 ;SUBTRACT AMT0 FROM TOTAL0 CLR C SUBB A,PRICE+1 CALL BCD_CONV MOV AMOUNT+2,A MOV A,AMOUNT+1 ;SUBTRACT AMT1 FROM TOTAL1 SUBB A,PRICE CALL BCD_CONV MOV AMOUNT+1,A MOV A,AMOUNT ;SUBTRACT AMT2 FROM TOTAL2 SUBB A,#00h CALL BCD_CONV MOV AMOUNT,A MOV R1,#AMOUNT ;store AMOUNT MOV R4,#0AH ;Starting Address IN EEPROM MOV R6,#3 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY MOV A,AMOUNT+1 CJNE A,#40H,FCX1 MOV BUZZ_COUNT,#02H SETB BUZZER FCX1: CJNE A,#38H,FAX1 MOV BUZZ_COUNT,#02H SETB BUZZER FAX1: CJNE A,#41H,FAAX1 MOV BUZZ_COUNT,#02H SETB BUZZER FAAX1: CJNE A,#20H,FCX2 MOV BUZZ_COUNT,#03H SETB BUZZER FCX2: CJNE A,#19H,FAX2 MOV BUZZ_COUNT,#03H SETB BUZZER FAX2: CJNE A,#21H,FAAX2 MOV BUZZ_COUNT,#03H SETB BUZZER FAAX2: CJNE A,#10H,FCX3 MOV BUZZ_COUNT,#04H SETB BUZZER FCX3: CJNE A,#11H,FCX4 MOV BUZZ_COUNT,#04H SETB BUZZER FCX4: CJNE A,#09H,FAX4 MOV BUZZ_COUNT,#04H SETB BUZZER FAX4: MOV A,AMOUNT+2 ;SUBTRACT AMT0 FROM TOTAL0 CLR C SUBB A,PRICE+1 CALL BCD_CONV MOV A,AMOUNT+1 ;SUBTRACT AMT1 FROM TOTAL1 SUBB A,PRICE MOV A,AMOUNT CLR TBIT JNC POP1 SETB TBIT POP1: CJNE A,#00H,BACK JNB TBIT, BACK MOV BALANCE,#00H MOV R1,#BALANCE ;store COUNT MOV R4,#15H ;Starting Address IN EEPROM MOV R6,#1 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY CLR RELAY SETB BUZZER BACK: RET ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BCD_CONV: CLR BCDCARRY CLR CARRY JNC LOP2 SETB CARRY LOP2: JNB AC,LOP1 SETB BCDCARRY CLR C SUBB A,#06H LOP1: JNB CARRY,LOP3 CLR C SUBB A,#60H LOP3: CLR C JNB CARRY,LOP4 SETB C LOP4: RET ;################################################# ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 ; READ PULSE COUNTER FROM MEMORY ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 READ_BALANCE: MOV R1,#BALANCE ;GET DATA IN BYTES(RAM) MOV R4,#15H ;DATA ADDRESS IN EEPROM MOV R6,#1 ;NUMBER OF BYTES CALL READ_EEPROM RET READ_COUNTER: MOV R1,#COUNTER ;GET DATA IN BYTES(RAM) MOV R4,#0EH ;DATA ADDRESS IN EEPROM MOV R6,#2 ;NUMBER OF BYTES CALL READ_EEPROM RET READ_PRICE: MOV R1,#PRICE ;GET DATA IN BYTES(RAM) MOV R4,#10H ;DATA ADDRESS IN EEPROM MOV R6,#2 ;NUMBER OF BYTES CALL READ_EEPROM RET ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 SEP_DISP1: MOV A,AMOUNT ANL A,#0F0H SWAP A CJNE A,#00H,DAP1 MOV A,AMOUNT ANL A,#0FH AJMP DAP3 DAP1: ADD A,#30H ;BOTH NOT EQUAL TO ZERO MOV R4,A CALL WRLCDDATA CALL MDELAY DAP2: MOV A,AMOUNT ANL A,#0FH ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY DAP4: MOV A,AMOUNT+1 ANL A,#0F0H SWAP A ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY DAP5: MOV A,AMOUNT+1 ANL A,#0FH ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY MOV R4,#'.' CALL WRLCDDATA CALL MDELAY MOV A,AMOUNT+2 ANL A,#0F0H SWAP A ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY MOV A,AMOUNT+2 ANL A,#0FH ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY RET DAP3: CJNE A,#00H,DAP2 ;CHK 2 DIGIT MOV A,AMOUNT+1 ANL A,#0F0H SWAP A CJNE A,#00H,DAP4 ;CHK 3 DIGIT AJMP DAP5 SEP_DISP: MOV A,TEMP ANL A,#0F0H SWAP A ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY MOV A,TEMP ANL A,#0FH ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY RET ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 AMT_RECHARGE: MOV READ_BYTE,#01H MOV READ_BYTE+1,#00H MOV READ_BYTE+2,#10H MOV R1,#READ_BYTE ;store COUNT MOV R6,#3 ;STORE 2 BYTES MOV A,#WTCMD1 ;LOAD WRITE COMMAND CALL OUTS ;SEND IT MOV A,#20H ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT BXLP: MOV A,@R1 ;GET DATA CALL OUT ;SEND IT INC R1 ;INCREMENT DATA POINTER DJNZ R6,BXLP ;LOOP TILL DONE CALL STOP ;SEND STOP CONDITION CALL DELAY RET STORE_UNIT_PRICE: MOV READ_BYTE,#00H MOV READ_BYTE+1,#01H MOV READ_BYTE+2,#00H MOV R1,#READ_BYTE ;store COUNT MOV R6,#3 ;STORE 2 BYTES MOV A,#WTCMD1 ;LOAD WRITE COMMAND CALL OUTS ;SEND IT MOV A,#20H ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT BALP: MOV A,@R1 ;GET DATA CALL OUT ;SEND IT INC R1 ;INCREMENT DATA POINTER DJNZ R6,BALP ;LOOP TILL DONE CALL STOP ;SEND STOP CONDITION CALL DELAY RET RESET_BALANCE: MOV BALANCE,#0FFH MOV R1,#BALANCE ;store COUNT MOV R4,#15H ;Starting Address IN EEPROM MOV R6,#1 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY RET RESET_PRICE: MOV PRICE,#02H MOV PRICE+1,#00H MOV R1,#PRICE ;store COUNT MOV R4,#10H ;Starting Address IN EEPROM MOV R6,#2 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY RET RESET_COUNTER: MOV COUNTER,#00H MOV COUNTER+1,#10H MOV R1,#COUNTER ;store COUNT MOV R4,#0EH ;Starting Address IN EEPROM MOV R6,#2 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY RET RESET_AMT: MOV AMOUNT,#00H ; MOV AMOUNT+1,#05H MOV AMOUNT+2,#00H MOV R1,#AMOUNT ;store READING MOV R4,#0AH ;Starting Address IN EEPROM MOV R6,#3 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY RET RESET_READING: MOV READING,#00H MOV READING+1,#05H MOV R1,#READING ;store READING MOV R4,#05H ;Starting Address IN EEPROM MOV R6,#2 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAY RET ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELAYY: MOV F1,#0FH SEP3: MOV F2,#0fFH SEP2: MOV F3,#0FFH SEP1: DJNZ F3,SEP1 DJNZ F2,SEP2 CALL CARD_READ MOV A,READ_BYTE CJNE A,#0FFH,DSP1 CLR TBIT1 DSP3A:DJNZ F1,SEP3 RET DELAYYS: MOV F1,#0FH S5P3: MOV F2,#0fFH S5P2: MOV F3,#0FFH S5P1: DJNZ F3,S5P1 DJNZ F2,S5P2 DJNZ F1,S5P3 RET DSP1: JB TBIT1,DSP3A CALL TITLE3 CALL DELAYS CALL DELAYS CALL CARD_READ MOV A,READ_BYTE CJNE A,#00H,DSP2 CALL TITLE4 ; NEW UNIT PRICE MOV PRICE,READ_BYTE+1 MOV PRICE+1,READ_BYTE+2 MOV R1,#PRICE ;store COUNT MOV R4,#10H ;Starting Address IN EEPROM MOV R6,#2 ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAYS SETB TBIT1 AJMP RESETX_CHIP DSP2: CJNE A,#01H,DSP3 CALL TITLE5 ; NEW RECHARGE ; MOV R1,#AMOUNT ;GET DATA IN BYTES(RAM) ; MOV R4,#0AH ;DATA ADDRESS IN EEPROM ; MOV R6,#03h ;NUMBER OF BYTES ; CALL READ_EEPROM MOV A,AMOUNT ADD A,READ_BYTE+1 DA A MOV AMOUNT,A MOV A,AMOUNT+1 ADDC A,READ_BYTE+2 DA A MOV AMOUNT+1,A MOV R1,#AMOUNT ;store READING MOV R4,#0AH ;Starting Address IN EEPROM MOV R6,#03h ;STORE 2 BYTES CALL STORE_EEPROM CALL DELAYS SETB TBIT1 CALL RESET_BALANCE RESETX_CHIP: MOV READ_BYTE,#0AAH ;ERASE AMOUNT MOV READ_BYTE+1,#0FFH MOV READ_BYTE+2,#0FFH MOV R1,#READ_BYTE ;store COUNT MOV R6,#3 ;STORE 2 BYTES MOV A,#WTCMD1 ;LOAD WRITE COMMAND CALL OUTS ;SEND IT MOV A,#20H ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT BBLP: MOV A,@R1 ;GET DATA CALL OUT ;SEND IT INC R1 ;INCREMENT DATA POINTER DJNZ R6,BBLP ;LOOP TILL DONE CALL STOP ;SEND STOP CONDITION CALL DELAY RET DSP3: CJNE A,#0AAH,DSP4 CALL TITLE6 ; NEW RECHARGE CALL DELAYS SETB TBIT1 DSP4: RET ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELAY: MOV R6,#0FFH RE1: MOV R7,#0FFH RE: NOP DJNZ R7,RE DJNZ R6,RE1 RET ;********************************************************** CARD_READ: MOV R1,#READ_BYTE ;GET DATA IN BYTES(RAM) MOV R6,#3 ;NUMBER OF BYTES MOV A,#WTCMD1 ;LOAD WRITE COMMAND TO SEND ADDRESS CALL OUTS ;SEND IT MOV A,#20H ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT MOV A,#RDCMD1 ;LOAD READ COMMAND CALL OUTS ;SEND IT BXDLP: CALL IN ;READ DATA MOV @R1,a ;STORE DATA INC R1 ;INCREMENT DATA POINTER DJNZ R6,AXLP ;DECREMENT LOOP COUNTER CALL STOP ;IF DONE, ISSUE STOP CONDITION RET ;DONE, EXIT ROUTINE AXLP: CLR SDA1 ;NOT DONE, ISSUE ACK SETB SCL1 NOP ;NOTE 1 NOP NOP NOP ;NOTE 2 NOP CLR SCL1 JMP BXDLP ;CONTINUE WITH READS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; READ DATA FROM EEPROM ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% READ_EEPROM: MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS CALL OUTS ;SEND IT MOV A,R4 ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT MOV A,#RDCMD ;LOAD READ COMMAND CALL OUTS ;SEND IT BRDLP: CALL IN ;READ DATA MOV @R1,a ;STORE DATA INC R1 ;INCREMENT DATA POINTER DJNZ R6,AKLP ;DECREMENT LOOP COUNTER CALL STOP ;IF DONE, ISSUE STOP CONDITION RET ;DONE, EXIT ROUTINE AKLP: CLR SDA1 ;NOT DONE, ISSUE ACK SETB SCL1 NOP ;NOTE 1 NOP NOP NOP ;NOTE 2 NOP CLR SCL1 JMP BRDLP ;CONTINUE WITH READS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; STORE DATA IN EEPROM ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STORE_EEPROM: MOV A,#WTCMD ;LOAD WRITE COMMAND CALL OUTS ;SEND IT MOV A,R4 ;GET LOW BYTE ADDRESS CALL OUT ;SEND IT BTLP: MOV A,@R1 ;GET DATA CALL OUT ;SEND IT INC R1 ;INCREMENT DATA POINTER DJNZ R6,BTLP ;LOOP TILL DONE CALL STOP ;SEND STOP CONDITION RET ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;########################################################## ; DISPLAY ROUTINES ;########################################################## TITLE1: MOV DPTR,#MSAG1 CALL LCD_MSG RET MSAG1: DB 1H,84H,'PREPAID',0C2H,'ENERGY METER',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISP_READING: MOV DPTR,#MSAG2 CALL LCD_MSG RET MSAG2: DB 1H,82H,'METER READING',0C6H,00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AMT_READING: MOV DPTR,#MSAG3 CALL LCD_MSG RET MSAG3: DB 1H,81H,'BALANCE AMOUNT',0C3H,'Rs.',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ COUNT_READING: MOV DPTR,#MSAG4 CALL LCD_MSG RET MSAG4: DB 1H,82H,'PULSE COUNT',0C6H,00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UNIT_PRICE: MOV DPTR,#MSAG14 CALL LCD_MSG RET MSAG14: DB 1H,83H,'UNIT PRICE',0C4H,'Rs ',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RECHAGRE: MOV DPTR,#MSAG5 CALL LCD_MSG RET MSAG5: DB 1H,80H,'Please Recharge',0C2H,'your Account',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE3: MOV DPTR,#MSAG6 CALL LCD_MSG RET MSAG6: DB 1H,84H,'New Card',0C1H,'** DETECTED **',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE4: MOV DPTR,#MSAG7 CALL LCD_MSG RET MSAG7: DB 1H,81H,'NEW UNIT PRICE',0C1H,'** STORED **',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE5: MOV DPTR,#MSAG8 CALL LCD_MSG RET MSAG8: DB 1H,83H,'NEW AMOUNT',0C1H,'** RECHARGED **',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE6: MOV DPTR,#MSAG9 CALL LCD_MSG RET MSAG9: DB 1H,82H,'INVALID CARD',0C0H,'****************',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SYSTEM_RESET: MOV DPTR,#MSAG91 CALL LCD_MSG RET MSAG91: DB 1H,80H,'System Restored',0C0H,'****************',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;********************************************************** ; INITIALIZE THE LCD 4-BIT MODE ;********************************************************** INITLCD4: CLR LCD_RS ; LCD REGISTER SELECT LINE CLR LCD_E ; ENABLE LINE MOV R4, #CONFIG; FUNCTION SET - DATA BITS, ; LINES, FONTS CALL WRLCDCOM4 MOV R4, #ONDSP ; DISPLAY ON CALL WRLCDCOM4 MOV R4, #ENTRYMODE ; SET ENTRY MODE CALL WRLCDCOM4 ; INCREMENT CURSOR RIGHT, NO SHIFT MOV R4, #CLRDSP; CLEAR DISPLAY, HOME CURSOR CALL WRLCDCOM4 RET ; ********************************************************** ; SOFTWARE VERSION OF THE POWER ON RESET ; ********************************************************** RESETLCD4: CLR LCD_RS ; LCD REGISTER SELECT LINE CLR LCD_E ; ENABLE LINE CLR LCD_DB7 ; SET BIT PATTERN FOR... CLR LCD_DB6 ; ... POWER-ON-RESET SETB LCD_DB5 SETB LCD_DB4 SETB LCD_E ; START ENABLE PULSE CLR LCD_E ; END ENABLE PULSE MOV A, #4 ; DELAY 4 MILLISECONDS CALL MDELAY SETB LCD_E ; START ENABLE PULSE CLR LCD_E ; END ENABLE PULSE MOV A, #1 ; DELAY 1 MILLISECOND CALL MDELAY SETB LCD_E ; START ENABLE PULSE CLR LCD_E ; END ENABLE PULSE MOV A, #1 ; DELAY 1 MILLISECOND CALL MDELAY CLR LCD_DB4 ; SPECIFY 4-BIT OPERATION SETB LCD_E ; START ENABLE PULSE CLR LCD_E ; END ENABLE PULSE MOV A, #1 ; DELAY 1 MILLISECOND CALL MDELAY MOV R4, #CONFIG; FUNCTION SET CALL WRLCDCOM4 MOV R4, #08H ; DISPLAY OFF CALL WRLCDCOM4 MOV R4, #1 ; CLEAR DISPLAY, HOME CURSOR CALL WRLCDCOM4 MOV R4,#ENTRYMODE ; SET ENTRY MODE ACALL WRLCDCOM4 JMP INITLCD4 ; ********************************************************** ; SUB RECEIVES A COMMAND WORD TO THE LCD ; COMMAND MUST BE PLACED IN R4 BY CALLING PROGRAM ; ********************************************************** WRLCDCOM4: CLR LCD_E CLR LCD_RS ; SELECT READ COMMAND PUSH ACC ; SAVE ACCUMULATOR MOV A, R4 ; PUT DATA BYTE IN ACC MOV C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS MOV LCD_DB4, C ; ONE BIT AT A TIME USING... MOV C, ACC.5 ; BIT MOVE OPERATOINS MOV LCD_DB5, C MOV C, ACC.6 MOV LCD_DB6, C MOV C, ACC.7 MOV LCD_DB7, C SETB LCD_E ; PULSE THE ENABLE LINE CLR LCD_E MOV C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE MOV LCD_DB4, C MOV C, ACC.1 MOV LCD_DB5, C MOV C, ACC.2 MOV LCD_DB6, C MOV C, ACC.3 MOV LCD_DB7, C CLR LCD_E SETB LCD_E ; PULSE THE ENABLE LINE CLR LCD_E CALL MADELAY POP ACC RET ; ********************************************************** ; SUB TO RECEIVE A DATA WORD TO THE LCD ; DATA MUST BE PLACED IN R4 BY CALLING PROGRAM ; ********************************************************** WRLCDDATA: CLR LCD_E SETB LCD_RS ; SELECT READ DATA PUSH ACC ; SAVE ACCUMULATOR MOV A, R4 ; PUT DATA BYTE IN ACC MOV C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS MOV LCD_DB4, C ; ONE BIT AT A TIME USING... MOV C, ACC.5 ; BIT MOVE OPERATOINS MOV LCD_DB5, C MOV C, ACC.6 MOV LCD_DB6, C MOV C, ACC.7 MOV LCD_DB7, C SETB LCD_E ; PULSE THE ENABLE LINE CLR LCD_E MOV C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE MOV LCD_DB4, C MOV C, ACC.1 MOV LCD_DB5, C MOV C, ACC.2 MOV LCD_DB6, C MOV C, ACC.3 MOV LCD_DB7, C CLR LCD_E SETB LCD_E ; PULSE THE ENABLE LINE CLR LCD_E NOP NOP POP ACC RET ; ********************************************************** ; SUB TAKES THE STRING IMMEDIATELY FOLLOWING THE CALL AND ; DISPLAYS ON THE LCD. STRING MUST BE TERMINATED WITH A ; NULL (0). ; ********************************************************** LCD_MSG: CLR A ; Clear Index MOVC A,@A+DPTR ; Get byte pointed by Dptr INC DPTR ; Point to the next byte JZ LCD_Msg9 ; Return if found the zero (end of stringz) CJNE A,#01H,Lcd_Msg1 ; Check if is a Clear Command MOV R4,A CALL WRLCDCOM4 ;If yes, RECEIVE it as command to LCD JMP LCD_MSG ;Go get next byte from stringz Lcd_Msg1: CJNE A,#0FFH,FLL ;Check for displaying full character MOV R4,A CALL WRLCDDATA JMP LCD_MSG FLL: CJNE A,#080h,$+3 ; Data or Address? If => 80h then is address. JC Lcd_Msg_Data ; Carry will be set if A < 80h (Data) MOV R4,A CALL WRLCDCOM4 ; Carry not set if A=>80, it is address JMP Lcd_Msg ; Go get next byte from stringz Lcd_Msg_Data: ; MOV R4,A CALL WRLCDDATA ; It was data, RECEIVE it to Lcd JMP Lcd_Msg ; Go get next byte from stringz Lcd_Msg9: RET ; Return to Caller ; ********************************************************** ; 1 MILLISECOND DELAY ROUTINE ; ********************************************************** MDELAY: PUSH ACC MOV A,#0A6H MD_OLP: INC A NOP NOP NOP NOP NOP NOP NOP NOP JNZ MD_OLP NOP POP ACC RET MADELAY: PUSH ACC MOV A,#036H MAD_OLP: INC A NOP NOP NOP NOP NOP NOP NOP NOP JNZ MAD_OLP NOP POP ACC RET ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELAYS: ;One second delay routine MOV R6, #00H ;put 0 in register R6 (R6 = 0) MOV R5, #04H ;put 5 in register R5 (R5 = 4) LOOPB: INC R6 ;increase R6 by one (R6 = R6 +1) ACALL DELAYMS ;call the routine above. It will run and return to here. MOV A, R6 ;move value in R6 to A JNZ LOOPB ;if A is not 0, go to LOOPB DEC R5 ;decrease R5 by one. (R5 = R5 -1) MOV A, R5 ;move value in R5 to A JNZ LOOPB ;if A is not 0 then go to LOOPB. RET ;************************************************************************** DELAYMS: ;millisecond delay routine ; ; MOV R7,#00H ;put value of 0 in register R7 LOOPA: INC R7 ;increase R7 by one (R7 = R7 +1) MOV A,R7 ;move value in R7 to Accumlator (also known as A) CJNE A,#0FFH,LOOPA ;compare A to FF hex (256). If not equal go to LOOPA RET ;return to the point that this routine was called from ;************************************************************************** ;*********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR ; to the EEPROM and includes START condition. Refer to the data sheets ; for discussion of START and STOP conditions. ;*********************************************************************** OUTS: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT SETB SDA1 ;INSURE DATA IS HI SETB SCL1 ;INSURE CLOCK IS HI NOP ;NOTE 1 NOP NOP CLR SDA1 ;START CONDITION -- DATA = 0 NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK = 0 OTSLP: RLC A ;SHIFT BIT JNC BITLS SETB SDA1 ;DATA = 1 JMP OTSL1 ;CONTINUE BITLS: CLR SDA1 ;DATA = 0 OTSL1: SETB SCL1 ;CLOCK HI NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK LOW DJNZ R2,OTSLP ;DECREMENT COUNTER SETB SDA1 ;TURN PIN INTO INPUT NOP ;NOTE 1 SETB SCL1 ;CLOCK ACK NOP ;NOTE 1 NOP NOP CLR SCL1 RET ;********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM ; without sending a START condition. ;********************************************************************** OUT: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT OTLP: RLC A ;SHIFT BIT JNC BITL SETB SDA1 ;DATA = 1 JMP OTL1 ;CONTINUE BITL: CLR SDA1 ;DATA = 0 OTL1: SETB SCL1 ;CLOCK HI NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK LOW DJNZ R2,OTLP ;DECREMENT COUNTER SETB SDA1 ;TURN PIN INTO INPUT NOP ;NOTE 1 SETB SCL1 ;CLOCK ACK NOP ;NOTE 1 NOP NOP CLR SCL1 RET STOP: CLR SDA1 ;STOP CONDITION SET DATA LOW NOP ;NOTE 1 NOP NOP SETB SCL1 ;SET CLOCK HI NOP ;NOTE 1 NOP NOP SETB SDA1 ;SET DATA HIGH RET ;******************************************************************* ; THIS ROUTINE READS A BYTE OF DATA FROM EEPROM ; From EEPROM current address pointer. ; Returns the data byte in R1 ;******************************************************************* CREAD: MOV A,#RDCMD ;LOAD READ COMMAND CALL OUTS ;SEND IT CALL IN ;READ DATA MOV R1,A ;STORE DATA CALL STOP ;SEND STOP CONDITION RET ;********************************************************************** ; THIS ROUTINE READS IN A BYTE FROM THE EEPROM ; and stores it in the accumulator ;********************************************************************** IN: MOV R2,#8 ;LOOP COUNT SETB SDA1 ;SET DATA BIT HIGH FOR INPUT INLP: CLR SCL1 ;CLOCK LOW NOP ;NOTE 1 NOP NOP NOP SETB SCL1 ;CLOCK HIGH CLR C ;CLEAR CARRY JNB SDA1,INL1 ;JUMP IF DATA = 0 CPL C ;SET CARRY IF DATA = 1 INL1: RLC A ;ROTATE DATA INTO ACCUMULATOR DJNZ R2,INLP ;DECREMENT COUNTER CLR SCL1 ;CLOCK LOW RET ;********************************************************************* ; This routine test for WRITE DONE condition ; by testing for an ACK. ; This routine can be run as soon as a STOP condition ; has been generated after the last data byte has been sent ; to the EEPROM. The routine loops until an ACK is received from ; the EEPROM. No ACK will be received until the EEPROM is done with ; the write operation. ;********************************************************************* ACKTST: MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT CLR SDA1 ;START CONDITION -- DATA = 0 NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK = 0 AKTLP: RLC A ;SHIFT BIT JNC AKTLS SETB SDA1 ;DATA = 1 JMP AKTL1 ;CONTINUE AKTLS: CLR SDA1 ;DATA = 0 AKTL1: SETB SCL1 ;CLOCK HI NOP ;NOTE 1 NOP NOP CLR SCL1 ;CLOCK LOW DJNZ R2,AKTLP ;DECREMENT COUNTER SETB SDA1 ;TURN PIN INTO INPUT NOP ;NOTE 1 SETB SCL1 ;CLOCK ACK NOP ;NOTE 1 NOP NOP JNB SDA1,EXIT ;EXIT IF ACK (WRITE DONE) JMP ACKTST ;START OVER EXIT: CLR SCL1 ;CLOCK LOW CLR SDA1 ;DATA LOW NOP ;NOTE 1 NOP NOP SETB SCL1 ;CLOCK HIGH NOP NOP SETB SDA1 ;STOP CONDITION RET ;********************************************************************* END
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?