Nisar
Joined: 16 Nov 2007 Posts: 20
|
Dip Switch and Seven Segment Display |
Posted: Sun Mar 15, 2009 11:07 am |
|
|
Hello every one
I want to count up on two seven segment displays from the binary values
set by the dip switches connected on PIC16F877 Port C.
Plz anybody help me in C code with dip switches.
This is my C code. Runs continuously from 00 to 99.
Code: | #include<16f877.h>
#fuses XT,NOLVP,NOWDT,PUT
#use delay (clock=4000000) // define crystal = 4MHz
#byte port_d=8
#byte port_a=5
byte CONST LED_MAP[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0x90};
//===========================================
// this function use to display number 00=99
// input : n = number to display
//===========================================
void display_number(int n)
{
output_d(LED_MAP[n/10]);//tens position;n=0 to 9
output_low(PIN_A1);
delay_ms(2);
output_high(PIN_A1);
output_d(LED_MAP[n%10]) ;//unit position
output_low(PIN_A0);
delay_ms(2);
output_high(PIN_A0);
}
//============================================
// main program
//============================================
void main()
{
int i,count=1;
while(TRUE)
{
for (i=0;i<=200;i++)
display_number(count); // dispay 200 times
count=(count==99) ? 1: count+1;//count+1=++count
}
} |
Thanks in advance.
Nisar Ahmed
+++++++++++++++
Locking.
Reason: No triple posting.
-- Forum Moderator
+++++++++++++++ |
|