Professional Documents
Culture Documents
Source Code:
#define SegOne 0x01
#define SegTwo 0x02
#define SegThree 0x04
#define SegFour 0x08
void main() {
char
seg_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,
0x8e};
int cnt, num, temp,i;
while (1)
{
for (cnt = 0x00; cnt <= 9999; cnt++) // loop to display 0-9999
{
for (i = 0; i < 100; i++)
{
num = cnt;
temp = num / 1000;
num = num % 1000;
PORTD = SegOne;
PORTB = seg_code[temp];
DELAY_ms(1);
Laboratory Activity:
Using the 7-Segment Display and the PIC16F877A microcontroller create a circuit that will
count the number of visitors entering the building and will count down if the person leaves the
building. Limit the counting to 9 only.
Do the following:
1. Schematic Diagram
2. Source Code
Questions:
1. Write below the specific code you use to count-up the numbers from 0-9?
Answer:
if (!PORTB.F1 && i<9)
{
i++;
PORTD = segdisplay[i];
delay_ms(50)
}
2. Write below the specific code you use to count-down the numbers from 9-0?
Answer:
if (!PORTB.F2 && i>0)
{
i--;
PORTD = segdisplay[i];
delay_ms(50);
}
3. Write the code in setting your ports as INPUT?
Answer:
TRISB.F1=1;
TRISB.F2=1;