Professional Documents
Culture Documents
#include <xc.h>
#include "pic16f877a.h"
#include "stdint.h"
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (XT
oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT
disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT
enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR
enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-
Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR
must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection
bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable
bits (Write protection off; all program memory may be written to by
EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection
bit (Code protection off)
volatile struct {
unsigned sayici1:1;
unsigned sayici2:1;
unsigned basildi1:1;
unsigned birakildi1:1;
unsigned basildi2:1;
unsigned birakildi2:1;
unsigned stop:1;
} Flags;
int main(void)
{
char sayi[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
int i=0;
TRISDbits.TRISD4 = 0;//seg6
TRISDbits.TRISD5 = 0;//seg8
TRISDbits.TRISD6 = 0;//seg9
TRISDbits.TRISD7 = 0;//seg12
TRISBbits.TRISB0 = 0;//seg5
TRISBbits.TRISB1 = 0;//seg4
TRISBbits.TRISB2 = 0;//seg3
TRISBbits.TRISB3 = 0;//seg2
TRISBbits.TRISB4 = 0;//seg1
TRISBbits.TRISB5 = 0;//seg7
TRISBbits.TRISB6 = 0;//seg10
TRISBbits.TRISB7 = 0;//seg11
Timer1_initialize();
while(1){
if(Flags.sayici1){
Flags.sayici1=0; i=i++;
if(i>60)i=0;
}
bin2dec(i);
dig0=sayi[ones];
dig1=sayi[tens];
dig2=sayi[hundreds];
dig3=sayi[thousands];
}
return 0;
}
{
if (TMR1IE && TMR1IF)
{
TMR1IF=0;
TMR1 = 40535;//65535-40535=25000... 25000*200ns=5ms
ss--;
if(ss==0){ss=Sayac1;
Flags.sayici1=1;}
digsay++;
if(digsay>3)digsay=0;
if(digsay==0)
{
B0=0;
B1=1;
B2=1;
B3=1;
PORTB=dig0;
}
else if(digsay==1)
{
B0=1;
B1=0;
B2=1;
B3=1;
PORTB=dig1;
}
else if(digsay==2)
{
B0=1;
B1=1;
B2=0;
B3=1;
PORTB=dig2;
}
else
{
B0=1;
B1=1;
B2=1;
B3=0;
PORTB=dig3;
}
}
}
void Timer1_initialize(void){
INTCONbits.GIE = 1; // ENABLE interrupts
INTCONbits.PEIE = 1; // ENable peripheral interrupts.
PIE1bits.TMR1IE=1;
PIR1bits.TMR1IF=0;
T1CON=0b00000000;
TMR1 = 53036;
T1CONbits.TMR1ON=1;
}
thousands++;
ADRES -= 1000;
}
else if(ADRES > 99 && ADRES <= 999)
{
hundreds++;
ADRES -=100;
}
else if(ADRES > 9 && ADRES <= 99)
{
tens++;
ADRES -= 10;
}
else if(ADRES <10){ones=ADRES;ADRES=0;}
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (XT
oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT
disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT
enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR
enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-
Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR
must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection
bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable
bits (Write protection off; all program memory may be written to by
EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection
bit (Code protection off)
volatile struct {
unsigned sayici1:1;
unsigned sayici2:1;
unsigned basildi:1;
unsigned birakildi:1;
unsigned basildi1:1;
unsigned birakildi1:1;
unsigned Mgirdi:1;
unsigned Stop:1;
} Flags;
Timer1_initialize();
i=0;
while(1){
if(Flags.sayici1){ Flags.sayici1=0;
i++;
Wrt_Signed_Int_LCD(i,0,0);
if(i>17)i=0;
}
return 0;
}
{
if (TMR1IE && TMR1IF)
{
TMR1IF=0;
TMR1 = 40535;
ss--;
if(ss==0){ss=Sayac1;
Flags.sayici1=1;}
ss1--;
if(ss1==0){ss1=Sayac2;
Flags.sayici2=1;
}
void Timer1_initialize(void){
INTCONbits.GIE = 1; // ENABLE interrupts
INTCONbits.PEIE = 1; // ENable peripheral interrupts.
PIE1bits.TMR1IE=1;
PIR1bits.TMR1IF=0;
T1CON=0b00000000;
TMR1 = 53036;
T1CONbits.TMR1ON=1;
}
#include <xc.h>
#include "pic16f877a.h"
#include "stdint.h"
#include "lcd1.h"
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (XT
oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT
disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT
enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR
enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-
Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR
must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection
bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable
bits (Write protection off; all program memory may be written to by
EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection
bit (Code protection off)
volatile struct {
unsigned sayici1:1;
unsigned sayici2:1;
unsigned basildi:1;
unsigned birakildi:1;
unsigned basildi1:1;
unsigned birakildi1:1;
unsigned Mgirdi:1;
unsigned Stop:1;
} Flags;
Timer1_initialize();
i=0;
while(1){
if(Flags.sayici1){ Flags.sayici1=0;
i++;
Wrt_Signed_Int_LCD(i,0,0);
if(i>17)i=0;
}
return 0;
}
{
if (TMR1IE && TMR1IF)
{
TMR1IF=0;
TMR1 = 40535;
ss--;
if(ss==0){ss=Sayac1;
Flags.sayici1=1;}
ss1--;
if(ss1==0){ss1=Sayac2;
Flags.sayici2=1;
}
void Timer1_initialize(void){
INTCONbits.GIE = 1; // ENABLE interrupts
INTCONbits.PEIE = 1; // ENable peripheral interrupts.
PIE1bits.TMR1IE=1;
PIR1bits.TMR1IF=0;
T1CON=0b00000000;
TMR1 = 53036;
T1CONbits.TMR1ON=1;
}