Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <reg51.h>
- unsigned char xdata LCD_A_ctrlRD _at_ 0x8012;
- unsigned char xdata LCD_A_ctrlWR _at_ 0x8010;
- unsigned char xdata LCD_A_dataWR _at_ 0x8011;
- unsigned char xdata LCD_A_dataRD _at_ 0x8013;
- unsigned char xdata PTWY _at_ 0x8008;
- unsigned char xdata PTAC0 _at_ 0x8005;
- unsigned char xdata PTAC1 _at_ 0x8006;
- unsigned char xdata PTAC2 _at_ 0x8007;
- unsigned char xdata PTAC _at_ 0x8000;
- unsigned char xdata PTSEG _at_ 0x8018;
- unsigned char xdata PTWY _at_ 0x8008;
- unsigned char xdata PTWE _at_ 0x8009;
- #define HOME 0x80
- #define INITDISP 0x38
- #define HOM2 0xC0
- #define LCDON 0x0F
- #define CLEAR 0x01
- #define SPEED 0xFFF
- void licz (void);
- void LCD_init (void);
- void LCD_dataWR (char);
- void LCD_ctrlWR (char);
- void put_message (char*);
- void Delay (unsigned int);
- void DELAY_HARWARE_50ms (void);
- unsigned int liczba[]={0,0,0,0};
- int licznik=0;
- main () {
- unsigned char i,k=0;
- LCD_init();
- put_message("MEMORY:");
- while (1) {
- unsigned int t1[]={0,1,2,3};
- unsigned int t2[]={63,6,91,79,102,109,125,7,127,111};
- for(i=0;i<4;i++) {
- P1=t1[i];
- PTSEG=t2[liczba[i]];
- PTAC2=0x00;
- DELAY_HARWARE_50ms();
- if(k==PTAC/4) {
- licz();
- k=0;
- }
- k++;
- if(k>PTAC/4)
- k=0;
- }
- }
- }
- void licz (void) {
- if((PTWE|0xFD)==0xFD) {
- if((PTWE|0xFE)!=0xFE)
- licznik--;
- if((PTWE|0xEF)==0xEF || licznik<0)
- licznik=9999;
- }
- else {
- if((PTWE|0xFE)!=0xFE)
- licznik++;
- if((PTWE|0xEF)==0xEF || licznik>9999)
- licznik=0;
- }
- liczba[3]=(licznik/1000);
- liczba[2]=(licznik-liczba[3]*1000)/100;
- liczba[1]=(licznik-liczba[3]*1000-liczba[2]*100)/10;
- liczba[0]=licznik-liczba[3]*1000-liczba[2]*100-liczba[1]*10;
- if((PTWE|0xDF)==0xDF) {
- LCD_ctrlWR(HOM2);
- LCD_dataWR(liczba[3]+0x30);
- LCD_ctrlWR(HOM2+1);
- LCD_dataWR(liczba[2]+0x30);
- LCD_ctrlWR(HOM2+2);
- LCD_dataWR(liczba[1]+0x30);
- LCD_ctrlWR(HOM2+3);
- LCD_dataWR(liczba[0]+0x30);
- }
- }
- void LCD_init () {
- LCD_ctrlWR(INITDISP);
- Delay(SPEED);
- LCD_ctrlWR(CLEAR);
- Delay(SPEED);
- LCD_ctrlWR(LCDON);
- }
- void LCD_dataWR (char val) {
- while(LCD_A_ctrlRD & 0x80);
- LCD_A_dataWR=val;
- }
- void LCD_ctrlWR (char val) {
- while(LCD_A_ctrlRD & 0x80);
- LCD_A_ctrlWR=val;
- }
- void put_message (char *s) {
- while(*s)
- LCD_dataWR(*s++);
- }
- void Delay (unsigned int time) {
- unsigned int i;
- for(i=0;i<time;i++);
- }
- void DELAY_HARWARE_50ms (void) {
- TMOD &=0xF0;
- TMOD|=0x01;
- ET0 = 0;
- TH0 = 0xF0;
- TL0 = 0xB0;
- TF0 = 0;
- TR0 = 1;
- while (TF0==0);
- TR0 = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement