Kumara
Joined: 16 Oct 2013 Posts: 7 Location: Sri Lanka
|
Driving Seven Segments ( C/C ) |
Posted: Thu Oct 17, 2013 3:36 am |
|
|
Dear Friends,
This is a CCS C code for driving two seven segments ( cathode common ).It is counting up to 99.
Code: |
#include <16F84A.h> // Pic Microcontroller (MCU) Select
#fuses NOWDT,HS, NOPUT, NOPROTECT // Fuses
#use delay(clock=20000000) // Crystal Oscillator Frequency ( 20 MHZ)
int count;
int k;
byte CONST LED_MAP[10] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; // LOOKUP TABLE FOR SSD
void display_number( int n )
{
for(k=0;k<=250;k++) // Delay ms250
{
output_b(LED_MAP[n/10 % 10]); // Left digit (10S) Pin_A4
output_high(PIN_A4);
delay_ms(2);
output_low(PIN_A4);
output_b(LED_MAP[n%10]); // Right digit (1S) Pin_A3
output_high(PIN_A3);
delay_ms(2);
output_low(PIN_A3);
}
}
void main() // Main block
{
int count=1,i;
while(TRUE) // Endless loop
{
for(i=0;i<=100;i++);
{
display_number(count);
count = (count==99) ? 1 : count+1;
}
}
}
|
|
|