I need to write only numbers (every second) in string on display (memory
mapped on 0x8001 adress) which are divding with 3 .
I must use counter not delay () for interrupt ...
I got with code below only to printing all numbers in one second.
I need 1 number per second, not all.
Anybody help?
1 | #include <reg51.h>
|
2 | #include <math.h>
|
3 | typedef unsigned char byte;
|
4 |
|
5 | byte a[8]= {7,5,16,3,1,4,11,9};
|
6 |
|
7 | byte counter;
|
8 | byte xdata display _at_ 0x8001;
|
9 | byte started = 0;
|
10 | int i=0;
|
11 |
|
12 | sbit switcher=P0^0;
|
13 |
|
14 | void Inic(void)
|
15 | {
|
16 | EA=1;
|
17 | TMOD=1;
|
18 | TH0=0x3C;
|
19 | TL0=0xAF;
|
20 | TR0=1;
|
21 | counter=1;
|
22 | }
|
23 |
|
24 |
|
25 | void timer0(void) interrupt 1 using 2
|
26 | {
|
27 | TH0=0x3C;
|
28 | TL0=0xAF;
|
29 |
|
30 | counter--;
|
31 | if(counter == 0)
|
32 | {
|
33 | counter = 20;
|
34 | if(started == 1)
|
35 | {
|
36 | if(i < 8)
|
37 | if(!(a[i]%3) )
|
38 | display=a[i];
|
39 | i++;
|
40 | if(i == 8)
|
41 | {
|
42 | ET0 = 0;
|
43 | TR0 = 0;
|
44 | started = 0;
|
45 | }
|
46 | }
|
47 | }
|
48 | }
|
49 |
|
50 | void main(void)
|
51 | {
|
52 | Inic();
|
53 | switcher = 1;
|
54 | while(1)
|
55 | {
|
56 | if(switcher == 0)
|
57 | if(started == 0)
|
58 | {
|
59 | started = 1;
|
60 | i = 0;
|
61 | counter = 20;
|
62 |
|
63 | TH0=0x3C;
|
64 | TL0=0xAF;
|
65 | ET0=1;
|
66 | TR0=1;
|
67 | }
|
68 | }
|
69 | }
|