Download digital interfacing and software
Transcript
5. Display module
is all but the last digit of number dec. In line 7–9, the bit for the decimal point is
set if dp was not zero. DISPLAY DP is a constant defined to be 0x80 in timer.h; it
is the output pattern for PC to display only the decimal point.
In a similar way, a function to display numbers in hexadecimal format can be
defined:
1
2
3
4
5
6
7
void display displaynumber hex(unsigned int number hex){
unsigned char i;
for(i=3; i!=0xFF; −−i){
current display [ i ] = display number mask[number hex & 0x0F];
number hex >>= 4;
}
}
This function is simpler as the one to display decimal values as no decimal point
is implemented and the modulo and division can be implemented in a shorter and
more efficient way.
5.2.3. Module initialization
The module initilization has to configure the all PC-pins and PA0 to PA3 as output pins and set the current display to a reasonable value (i.e. not to display
anything). Furthermore, it installs a callback to call the display update function
after every 4ms.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void display init (void){
unsigned char i;
for(i=0; i<4; ++i)
current display [ i ] = 0x00;
last updated digit = 0;
PCADDR = ALT FUNC;
PCCTL = 0x00;
PCADDR = DATA DIR;
PCCTL = 0x00;
PAADDR = ALT FUNC;
PACTL &= 0xF0;
PAADDR = DATA DIR;
PACTL &= 0xF0;
callback add(CALLBACK MODE CONTINUOUS,
DISPLAY UPDATE PERIOD, &display update);
}
In lines 6–9, all PC-pins are configured as general purpose output pins. In lines
10–13, the same is done for PA0–PA3. For the usage of callback add in line 14 see
section 4.1; DISPLAY UPDATE PERIOD is defined to be 4000 s, i.e. 4ms. That results
in a update period for all digits of 16ms giving an update frequency just above
50Hz below which flickering is getting noticeable.
µ
36