#include <16F877.h>
#device adc=8
#fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use delay(clock=4000000)
#define sw_up pin_a0 // SWITCH UP
#define sw_down pin_a1 // SWITCH DOWN
INT8 COUNT,A,B;
int8 num[10] ={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//common anode
//int8 Segment[10] ={ 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x27,0x7F,0x6F};//common cathode 0 1 2 3 4 5 6 7 8 9
// 0 1 2 3 4 5 6 7 8 9
VOID HEX_BCD(INT8 VAL);
void main(){
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
OUTPUT_LOW(PIN_E1);
OUTPUT_LOW(PIN_E0);
COUNT=0;
WHILE(true){
IF(!INPUT(SW_up)) {IF(COUNT++>99)COUNT=0; delay_ms(150);}
IF(!INPUT(SW_down)){IF(COUNT --<1)COUNT=99;delay_ms(150);}
HEX_BCD(COUNT);
OUTPUT_D(NUM[B]); // nuoy
OUTPUT_HIGH(PIN_E0);
DELAY_MS(10);
OUTPUT_LOW(PIN_E0);
OUTPUT_D(NUM[A]); // sib
OUTPUT_HIGH(PIN_E1);
DELAY_MS(10);
OUTPUT_LOW(PIN_E1);
DELAY_MS(200);
}
}
VOID HEX_BCD(INT8 VAL)
{ A=0;B=0;
WHILE(VAL>=10)
{
A++;
VAL-=10;
}
B=VAL;
}
Related projects
PICDEM FS USB Mass Storage Device using PIC18F4550 with Proteus Simulation
Introduction This microcontroller project demonstrates how to simulate a USB Mass Storage Device (MSD) using the PIC18F4550 in a Proteus simulation environment....
Peripheral TutorialsHands-On Digital I/O Lab with PIC18F46K22 Microcontroller
PIC18F46K22 Microcontroller Digital I/O specifically explores the design of simple combinational circuits using the digital I/O capabilities of the PIC18F46K22 microcontroller. Moving...
Peripheral TutorialsDesign for manufacturing and assembly: DFA&DFM
Product developers understand the challenges involved in creating a market-ready product. Even experienced designers often go through multiple prototype iterations before reaching...
Peripheral Tutorials · PIC16F877AKeypad 4×5 for microcontrollers v. 1.1 using PIC16F877
What's this? The circuit here described is a simple 4x5 keypad that can be used in particular with the PIC 16F877 microcontroller,...
Peripheral TutorialsMatrix scankey 3×4 for Lcd 2 line For CSS Compiler
Peripheral Tutorials · PIC16F877APIC16F877 timer1 code and Proteus simulation
This PIC16F877 microcontroller tutorial answers the question, " How to use timer1 of PIC16F877 and how to handle its interrupts? " Using...