* P2MX683isrtimersimple 20240401
* description:LED brightness using tiemrs and interrupts
* Uses Timer0 for a run monitor LED (toggles at a set rate)
* Uses Timer1 to trigger button debouncing and duty cycle updates (every 20ms)
* Uses Timer2 to generate a timing reference for soft PWM (period 50uS
* Brightness increases with button press (duty cycle increases)
* board: Curiosity development with 12F683 5V INTOSC 8MHz
* MPU; PIC12F683 DIP8P INTOSC8MHz
* Flash:2KW, RAM:128B,EEPROM 256Byte
* language: C XC8 v2.46 C99
* IDE: MPLABX v6.20, XC8 v2.46
* debug tool: PICkit3/PICkit4, High voltage programming mode
* measuring tool: kyutech arduino scope on processing4 windows11
//------------------------------------------------
* PIC12F683 DIP 8Pin on Curiosity development board
5V 1 VDD VSS 8 GND
2 GP5 GP0 7 ICSPDAT
BUT4 3 GP4 GP1 6 ICSPCLK LED monitor
RST S2 4 GP3/MCLR GP2/CCP1 5 LED softPWM OUT
*/
//INTOSCIO 8MHz Disable watchdog timer, Enable master clear on reset
#pragma config FOSC=INTOSCIO, WDTE=OFF, PWRTE=OFF, MCLRE=ON
#pragma config CP= OFF, CPD=OFF, BOREN=ON, IESO=ON, FCMEN=ON
#include
#define _XTAL_FREQ 8000000
#define SPK2 GP2 // LED2 for spftPWM
#define LED1 GP1 // LED1 for run monitor
#define BUT4 GP4 // bytton for set softPWM duty
unsigned char period=0;
unsigned char duty =0;
unsigned int blinkCounter=0;
unsigned int blinkRate=10;
void gpioBegin(void); //initialize I/O configuration.
void timer0Begin(void); // initialize timer0
void timer1Begin(void); // initialize timer1 peroid 20mS for read button
void timer2Begin(void); // initialize timer2 perois 50us for sort pwm
//-------------------------------------------------
void main(void) {
gpioBegin(); // Initializes General Purpose Input/Output (GPIO) pins.
timer0Begin();
timer1Begin();
timer2Begin();
PEIE=1; // : Peripheral Interrupt Enable bit
GIE=1; // enable dlobal interrupt
while (1){};// end while
}// end main
//-----------------------------------------------
void __interrupt() timerIsr(){
if(TMR0IF){ //Timer0 register has overflowed (must be cleared in software)
TMR0IF=0;
blinkCounter++; // for run monitor
if (blinkCounter >= blinkRate) {
// LED1 =!LED1; // LED Toggle run monitor LED
blinkCounter = 0; // Reset blink counter
}
}
if(TMR2IF){ //Timer2 register has overflowed (must be cleared in software)
TMR2IF=0;
period++;//This creates a basic timing reference for the soft PWM
if(period==255)period = 0;
if(period>=duty)GP2=1;// period >= to duty, the LED is turned on.
if(period pins changed state (must be cleared in software)
0 = None of the GPIO <5:0> pins have changed state
*/
/*
PIE1: PERIPHERAL INTERRUPT ENABLE REGISTER 1
EEIE ADIE CCP1IE — CMIE OSFIE TMR2IE TMR1IE
bit 7 EEIE: EE Write Complete Interrupt Enable bit
1 = Enables the EE write complete interrupt
0 = Disables the EE write complete interrupt
bit 6 ADIE: A/D Converter (ADC) Interrupt Enable bit
1 = Enables the ADC interrupt
0 = Disables the ADC interrupt
bit 5 CCP1IE: CCP1 Interrupt Enable bit
1 = Enables the CCP1 interrupt
0 = Disables the CCP1 interrupt
bit 4 Unimplemented: Read as ‘0’
bit 3 CMIE: Comparator Interrupt Enable bit
1 = Enables the Comparator 1 interrupt
0 = Disables the Comparator 1 interrupt
bit 2 OSFIE: Oscillator Fail Interrupt Enable bit
1 = Enables the oscillator fail interrupt
0 = Disables the oscillator fail interrupt
bit 1 TMR2IE: Timer2 to PR2 Match Interrupt Enable bit
1 = Enables the Timer2 to PR2 match interrupt
0 = Disables the Timer2 to PR2 match interrupt
bit 0 TMR1IE: Timer1 Overflow Interrupt Enable bit
1 = Enables the Timer1 overflow interrupt
0 = Disables the Timer1 overflo
*/