-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsevenSegmentCode.c
More file actions
55 lines (50 loc) · 1.44 KB
/
Copy pathsevenSegmentCode.c
File metadata and controls
55 lines (50 loc) · 1.44 KB
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
#include <lpc214x.h>
unsigned char getAlphaCode(unsigned char alphachar)
{
switch (alphachar)
{
// dp g f e d c b a - common anode: 0 segment on, 1 segment off
case '0': return 0xc0;
case '1': return 0xf9;
case '2': return 0xa4;
case '3': return 0xb0;
case '4': return 0x99;
case '5': return 0x92;
case '6': return 0x82;
case '7': return 0xf8;
case '8': return 0x80;
case '9': return 0x98;
//simmilarly add for other digit/characters
default : break;
}
return 0xff;
}
void alphadisp7SEG(char *buf)
{
unsigned char i,j;
unsigned char seg7_data,temp=0;
for(i=0;i<5;i++) // because only 5 seven segment digits are present
{
seg7_data = getAlphaCode(*(buf+i));
// instead of this look up table can be used
// to shift the segment data(8bits)to the hardware (shift registers) using Data,Clock,Strobe
for (j=0 ; j<8; j++)
{
//get one bit of data for serial sending
temp = seg7_data & 0x80; // shift data from Most significan bit (D7)
if(temp == 0x80)
IOSET0 |= 1 << 19; //IOSET0 | 0x00080000;
else
IOCLR0 |= 1 << 19; //IOCLR0 | 0x00080000;
//send one clock pulse
IOSET0 |= 1 << 20; //IOSET0 | 0x00100000;
delay_ms(1);
IOCLR0 |= 1 << 20; //IOCLR0 | 0x00100000;
seg7_data = seg7_data << 1; // get next bit into D7 position
}
}
IOSET0 |= 1 << 30; //IOSET0 | 0x40000000;
delay_ms(1); //nop();
IOCLR0 |= 1 << 30; //IOCLR0 | 0x40000000;
return;
}