You are on page 1of 6

Problema cu timere

Aici e Fisier.c

#include <xc.h>

#include "newxc8_header.h"

void main(void) {

Init();

while(1)

void Init() // functie de initizlizare

ANSEL = 0; //12F675 Only

TRISIO = 0b00000000; //GPI0= out

GPIO = CLEAR_PORT; //Clear GPIO

VRCON = CLEAR; //Turn Off Voltage Reference Peripheral

CMCON = 0x07; //Turn Off Comparator Peripheral

TMR0 = CLEAR; //Clear Timer0

OPTION_REG = FASTFLASHING; //Set Timer0 Prescaler To Fast Flash LED's

//IOCB3 = SET; //GP3 Interrupt On Pin Changed Enabled

//GPIE = SET; //Interrupt On Pin Change Enabled

T0IE = SET; //Timer0 Overflow Interrupt Enabled

T0IF = CLEAR; //Clear Timer0 Overflow Interrupt Flag

//GPIF = CLEAR; //Clear Interrupt On Pin Change Flag

GIE = SET; //Enable All Interrupts

return;

}
void __interrupt() Timer0_ISR(void)

if ( (T0IE & T0IF) == SET) //If A Timer0 Interrupt, Then

T0IF = CLEAR; //Clear Timer0 Interrupt Flag

++cont;

if(cont==120) // intrerupere dupa 2s: Tinstr=1us;Fosc

// INTCLK =Fosc/4 =1MHz

// Timer0CLK=1MHz/Prescaler =1MHz/64=15625

// Timer0 Tcyc time =1/Timer0CLK =64us

//load timer0 with 255 count, it will take 16.32ms (64usx255)

//1s/16.32ms= 61 interrupt counts to indicate 1second has been counted.

//dupa 2 secunde contorul devine 120 atunci vreau sa aprind intermitent LED-urile

LED1ON(); //Aprinde LED1

Delay(1); // Tine LED1 aprins timp de 1 secunda

GPIO = CLEAR_PORT; // Stinge LED1

LED2ON(); //Aprinde LED2

Delay(1); // Tine LED2 aprins timp de 1 secunda

GPIO = CLEAR_PORT; // Stinge LED2

cont=0;

return;

void LED1ON() // functie care aprinde led1

TRISIO=0b11111110; // Seteaza GP0 ca pin de iesire LED1

GPIO=0b00000001; /GP0 pune 5V pe pin GP0 - porneste LED1

return;
}

void LED2ON() // functie care aprinde led1

TRISIO=0b11111101; // Seteaza GP1 ca pin de iesire pt LED2

GPIO=0b00000010; //GP0 pune 5V pe pin GP0 - porneste LED2

return;

//***************************************************************************

//Delay(value) - Delay Routine

// - Delay=value*1s (When OSC=4MHZ)

//***************************************************************************

void Delay(char value) //functie care introduce delay de 1 secunda

for(i=0;i<value;i++)

for(j=0;j<100;j++)

__delay_ms(10);

return;

Aici e Fisier.h

#ifndef XC_HEADER_TEMPLATE_H

#define XC_HEADER_TEMPLATE_H

#include <pic.h> // include processor files - each processor file is guarded.


__CONFIG(INTIO & WDTDIS & MCLRDIS & BORDIS & UNPROTECT & PWRTEN);

#define _XTAL_FREQ 4000000 // Frecventa 4Mhz

//Defines

#define FASTFLASHING 0b10000101 //prescaler 64

//#define SLOWFLASHING 0b10000101 //This Value Is Xored With FASTFLASHING In The Isr

#define SET 1

#define CLEAR 0

#define CLEAR_PORT 0b00000000;

#define TRUE 1

#define FALSE 0

unsigned char cont=0;

unsigned char value;

unsigned char i,j;

void Init();

void LED1ON();

void LED2ON();

void Delay(char value);

#endif
Problema cu compararea tensiunii si aprindere 1 LED

Are doar Fisier.c

#include <xc.h>

// Configuration

#pragma config FOSC = INTRCIO // Oscillator Selection (INTOSC oscillator: I/O function on
GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)

#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)

#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)

#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)

#pragma config BOREN = OFF // Brown-out Reset Disable (Brown-out Reset disabled)

#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code
protection is disabled)

#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is
disabled)

void Initializare_comp();

//void LED();

//***************************************************************************

//Main() - Main Routine

//***************************************************************************

void main()

Initializare_comp(); //Initialize 12F629 Microcontroller

while(1) //Loop Forever

// LED();

//***************************************************************************

//Init - Initialization Routine

//***************************************************************************

void Initializare_comp() // functie de initializare a comparatorului apelata inaintea main


{

GPIO = 0; //initial sterg tot portul Clear GPIO

TRISIO = 0b11101011; //Pini 0,1 IN, 2OUT(iesire comparator)

ANSEL = 0b00000000; //Configure to AN0 - Remove for 16F629 -seteaza pini ca digitali

VRCON = 0b10101100; //Used to configure Reference to Comparator 12/24*5=2,5V tensiune


de referinta seteaza tensinea de referinta la 2,5V(Vdd/2)

CMCON = 0b00011101; // Used to configure Comparator-comp cu Vref

// GPO -in

GIE = 0; // Disable All Interrupts

return;

You might also like