0% found this document useful (0 votes)
18 views1 page

Micro

This code defines variables and functions for displaying a number on a 4-digit 7-segment display. It includes interrupt handling for a timer and button presses. The main loop decrements or increments the displayed number when buttons are pressed, with overflow handling, and calls the display function to refresh the display.

Uploaded by

ayariii50121651
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Micro

This code defines variables and functions for displaying a number on a 4-digit 7-segment display. It includes interrupt handling for a timer and button presses. The main loop decrements or increments the displayed number when buttons are pressed, with overflow handling, and calls the display function to refresh the display.

Uploaded by

ayariii50121651
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include "Display_utils.

h" if (oldstate2 && button(&PORTB,0,1,0)){


unsigned short shifter,portd_index; oldstate2 = 0;
unsigned int digit,number,oldstate,oldstate1,oldstate2,oldstate3,number1; number1++;
unsigned short portd_array[4]; if(number1 > 99)
void interrupt(){ number1 = 0;
PORTA = 0; Display();
PORTD = portd_array[portd_index]; }
PORTA = shifter; if(button(&PORTB,1,1,1)){
oldstate = 0; oldstate3 = 1;
oldstate1 = 0; }
oldstate2 = 0; if (oldstate3 && button(&PORTB,1,1,0)){
oldstate3 = 0; oldstate3 = 0;
shifter <<= 1; number1--;
if (shifter > 8u) if(number1 > 99)
shifter = 1; number1 = 99;
Display();
portd_index++; }
if (portd_index > 3u)
portd_index = 0; }while(1);
TMR0 = 0; }
INTCON.TMR0IF = 0;
} #include "Display_utils.h"
void Display(){ unsigned short shifter,portd_index;
digit = (number /10u); unsigned int digit,number,j;
portd_array[1] = conversion(digit); unsigned short portd_array[4];
digit = number%10u;
portd_array[0] = conversion(digit); void interrupt(){
digit = (number1 /10u); PORTA = 0;
portd_array[3] = conversion(digit); PORTD = portd_array[portd_index];
digit = number1%10u; PORTA = shifter;
portd_array[2] = conversion(digit);
Delay_ms(50); shifter <<= 1;
} if (shifter > 8u)
void main() { shifter = 1;
ADCON1 = 0x06;
TRISA = 0; portd_index++;
PORTA = 0; if (portd_index > 3u)
TRISD = 0; portd_index = 0;
PORTD = 0; TMR0 = 0;
OPTION_REG = 0x84; INTCON.TMR0IF = 0;
TMR0 = 0; }
digit = 0; Display(){
portd_index = 0;
shifter = 1; digit = (number /10u)%10u;
number = 0; portd_array[1] = conversion(digit);
number1 = 0;
INTCON = 0xa0; digit = number%10u;
Display(); portd_array[0] = conversion(digit);
do{
if(button(&PORTB,4,1,1)){ Delay_ms(200);
number = 0;
Display(); }
} void main() {
if(button(&PORTB,5,1,1)){ ADCON1 = 0x06;
number1 = 0; TRISA = 0;
Display(); PORTA = 0; number--;
} TRISD = 0; if(number > 3)
if(button(&PORTB,2,1,1)){ PORTD = 0; number = 3;
oldstate = 1; OPTION_REG = 0x84; Display();
} TMR0 = 0; }
if (oldstate && button(&PORTB,2,1,0)){ digit = 0;
oldstate = 0; portd_index = 0; for(j = 0 ;j <= 30 ;J++){
number++; shifter = 1; PORTC=36;
if(number > 99) number = 0;
number = 0; INTCON = 0xa0; number--;
Display(); j=0; if(number > 30)
} TRISC = 0; number = 30;
PORTC = 0; Display();
if(button(&PORTB,3,1,1)){ }
oldstate1 = 1;
} do{ for(j = 0 ;j <= 3 ;J++){
if (oldstate1 && button(&PORTB,3,1,0)){ PORTC=66;
oldstate1 = 0; for(j = 0 ;j <= 20 ;J++){
number--; PORTC=129; number--;
if(number > 99) number--; if(number > 3)
number = 99; if(number > 20) number = 3;
Display(); number = 20; Display();
} Display(); }
}
if(button(&PORTB,0,1,1)){ }while(1);
oldstate2 = 1; for(j = 0 ;j <= 3 ;J++){ }
} PORTC=66;

You might also like