#include
Sbit ADDR0 P1=^ 0;
P1 sbit ADDR1=^ 1;
Sbit ADDR2=p ^ 2;
Sbit ADDR3 P1=^ 3;
Sbit ENLED=P1 ^ 4;
Unsigned char code image [10] [8]={
{0 XFF, xc3 0, 0 XDB, 0 XDB, 0 XDB, 0 XDB, 0 XDB, 0 xc3},//show 0
Xe7 xe7 {0 XFF, 0, 0, 0 xe7, 0 xe7, 0 xe7, 0 xe7, 0 XFF},//show 1
Xe7 {0 XFF, 0, 0 XDB, 0 XDF, 0 xef, 0 xf7, xc3 0, 0 XFF},//show 2
XDF xe3 {0 XFF, 0, 0, 0 XDF, xc3 0, 0 XDF, 0 XDF, 0 xe3},//display 3
{xe7 0 XFF, 0, 0 xeb, 0 xed, 0 x81, 0 xef, 0 xef, 0 xef},//show 4
Xc3 {0 XFF, 0, 0 XFB, 0 XFB, xc3 0, 0 XDF, 0 XDF, 0 xc3},//show 5
Xc3 {0 XFF, 0, 0 XFB, 0 XFB, xc3 0, 0 XDB, 0 XDB, 0 xc3},//show 6
Xc3 {0 XFF, 0, 0 XDF, 0 XDF, 0 XDF, 0 XDF, 0 XDF, 0 XDF},//show 7
Xc3 {0 XFF, 0, 0 XDB, 0 XDB, xc3 0, 0 XDB, 0 XDB, 0 xc3},//8
Xc3 {0 XFF, 0, 0 XDB, 0 XDB, xc3 0, 0 XDF, 0 XDF, 0 xc3},//show 9
};
Void main ()
{
EA=1;//can make the total interruption
ENLED=0;
ADDR3=0;
TMOD=0 x01;//set the T0 to mode 1
XFC TH0=0;//for given initial value 0 xfc67 T0, timer 1 ms
X67 TL0=0;
ET0=1;//can make T0 break
TR0=1;//start T0
While (1);
}
Void InterruptTimer0 () interrupt 1
{
The static unsigned char I=0;//dynamic scanning index
The static unsigned char TMR=0;//1 s software timer
The static unsigned char index=9;//picture refresh index
XFC TH0=0;//reload the initial value
X67 TL0=0;
P0=0 XFF;//show the blanking
The switch (I)
{
Case 0: ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=image [index] [0]; break;
Case 1: ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=image [index] [1]; break;
Case 2: ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=image [index] [2]; break;
Case 3: ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=image [index] [3]; break;
Case 4: ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=image [index] [4]; break;
Case 5: ADDR2=1; ADDR1=0; ADDR0=1; i++; P0=image [index] [5]; break;
Case 6: ADDR2=1; ADDR1=1; ADDR0=0; i++; P0=image [index] [6]; break;
Case 7: ADDR2=1; ADDR1=1; ADDR0=1; i=0; P0=image [index] [7]; break;//show 9
Default: break;
}
//the code below to complete a second change a frame image
Tmr++;
If (TMR & gt;=1000)//reaches 1000 ms to change an image index
{
TMR=0;
//index++;
If (index==0)//picture index 0 ~ 9 cycle
{
The index=9;
} the else
{
The index -;
}
}
}
The problem is when I wrote the if (TMR & gt;=1000), dot matrix display only 9, but changed to 250 dot matrix display properly when the countdown effect, I think, since the 250 ms program can realize (just picture refresh fast, 250 ms change a number), then the interrupt and picture refresh implements should be normal, best can't find the reason, please answer,
CodePudding user response:
Case 7: ADDR2=1; ADDR1=1; ADDR0=1; i=0; P0=image [index] [7]; break;//show 9This comment is wrong, didn't pay attention to when editing
CodePudding user response:
TMR is defined as an unsigned char, variable maximum value is 256, you have a 1000 certainly not line, overflow! Pay attention to the variables defined types, int can insteadCodePudding user response:
Problem has been solved! Thank you very much, later I will remember this error in the process of programming!CodePudding user response:
Hello, have a great god to explain this, the novice small whiteCase 0: ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=image [index] [0]; break;
Case 1: ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=image [index] [1]; break;
Case 2: ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=image [index] [2]; break;
Case 3: ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=image [index] [3]; break;
Case 4: ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=image [index] [4]; break;
Case 5: ADDR2=1; ADDR1=0; ADDR0=1; i++; P0=image [index] [5]; break;
Case 6: ADDR2=1; ADDR1=1; ADDR0=0; i++; P0=image [index] [6]; break;
Case 7: ADDR2=1; ADDR1=1; ADDR0=1; i=0; P0=image [index] [7]; break;