Asanka Lakmal Morawaka
Newbie level 4
- Joined
- Nov 7, 2014
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 32
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include "Display_utils.h"
unsigned short shifter, portd_index;
unsigned int digit, number;
unsigned short portd_array[4];
void interrupt() {
PORTA = 0; // Turn off all 7seg displays
PORTD = portd_array[portd_index]; // bring appropriate value to PORTD
PORTA = shifter; // turn on appropriate 7seg. display
// move shifter to next digit
shifter <<= 1;
if (shifter > 8u)
shifter = 1;
// increment portd_index
portd_index++ ;
if (portd_index > 3u)
portd_index = 0; // turn on 1st, turn off 2nd 7seg.
TMR0L = 0; // reset TIMER0 value
INTCON = 0x20; // Clear T0IF
}//~
void main() {
//ANSEL = 0; // Set AN pins to Digital I/O
//ANSELH = 0;
OPTION_REG = 0x80; // Timer0 settings
digit = 0;
portd_index = 0;
shifter = 1;
TMR0L = 0;
INTCON = 0xA0; // Enable GIE, T0IE
PORTA = 0;
TRISA = 0; // Set PORTA as output
PORTD = 0;
TRISD = 0; // Set PORTD as output
number = 6789; // some initial value
do {
digit = number / 1000u ; // extract thousands digit
portd_array[3] = mask(digit); // and store it to PORTD array
digit = (number / 100u) % 10u; // extract hundreds digit
portd_array[2] = mask(digit); // and store it to PORTD array
digit = (number / 10u) % 10u; // extract tens digit
portd_array[1] = mask(digit); // and store it to PORTD array
digit = number % 10u; // extract ones digit
portd_array[0] = mask(digit); // and store it to PORTD array
Delay_ms(1000); // one second delay
number++ ; // increment number
if (number > 9999u)
number = 0;
} while(1); // endless loop
}