Initial commit
This commit is contained in:
		
							
								
								
									
										44
									
								
								03-software/ch/kb28/blinkerProject/app/factory/factory.c
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										44
									
								
								03-software/ch/kb28/blinkerProject/app/factory/factory.c
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| #include "factory.h" | ||||
|  | ||||
|  | ||||
| //the factory object containing all objects of our system | ||||
| static Factory theFactory; | ||||
|  | ||||
|  | ||||
| //all the getters | ||||
| LED* l() | ||||
| { | ||||
|     return &theFactory.l_; | ||||
| } | ||||
| LED* l2(){ | ||||
|     return &theFactory.l2_; | ||||
| } | ||||
|  | ||||
| LEDBlinker* lb() { | ||||
|     return &theFactory.lb_; | ||||
| } | ||||
|  | ||||
| LEDBlinker* lb2() { | ||||
|     return &theFactory.lb2_; | ||||
| } | ||||
|  | ||||
| //initialize all objects | ||||
| void Factory_init() | ||||
| { | ||||
|     LED_init(l(),LID); | ||||
|     LED_init(l2(),2); | ||||
|     LED_initHW(l()); | ||||
|     LED_initHW(l2()); | ||||
| } | ||||
|  | ||||
| //connect objects if required | ||||
| void Factory_build() | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| //start all state machines | ||||
| void Factory_start() { | ||||
|     LEDBlinker_startBehaviour(lb()); | ||||
|     LEDBlinker_startBehaviour(lb2()); | ||||
| } | ||||
							
								
								
									
										36
									
								
								03-software/ch/kb28/blinkerProject/app/factory/factory.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										36
									
								
								03-software/ch/kb28/blinkerProject/app/factory/factory.h
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| /* this is the Factory class */ | ||||
|  | ||||
|  | ||||
| #ifndef FACTORY_ONCE | ||||
| #define FACTORY_ONCE | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include <stdbool.h> | ||||
|  | ||||
| #include "../../board/led/led.h" | ||||
| #include "../ledblinker.h" | ||||
| #define LID 5 | ||||
|  | ||||
|  | ||||
| struct Factory_ | ||||
| { | ||||
|     LED l_; | ||||
|     LED l2_; | ||||
|     LEDBlinker lb_; | ||||
|     LEDBlinker lb2_; | ||||
| }; | ||||
|  | ||||
|  | ||||
| typedef struct Factory_ Factory; | ||||
|  | ||||
| void Factory_init(); | ||||
| void Factory_build(); | ||||
| void Factory_start(); | ||||
|  | ||||
| //these are global getters for our objects | ||||
| LED* l(); | ||||
| LED* l2();  | ||||
| LEDBlinker* lb(); | ||||
| LEDBlinker* lb2(); | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										68
									
								
								03-software/ch/kb28/blinkerProject/app/lebblinker.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								03-software/ch/kb28/blinkerProject/app/lebblinker.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| #include "ledblinker.h" | ||||
| #include "factory/factory.h" | ||||
| #include "../board/led/led.h" | ||||
|  | ||||
| void LEDBlinker_init(LEDBlinker* me) | ||||
| { | ||||
|     me->state = ST_LBINIT; | ||||
| } | ||||
|  | ||||
| void LEDBlinker_startBehaviour(LEDBlinker* me) | ||||
| { | ||||
|     POST(me, &LEDBlinker_processEvent, evLBInit,0,0); | ||||
| } | ||||
|  | ||||
| bool LEDBlinker_processEvent(Event* ev) | ||||
| { | ||||
|     bool processed = false; | ||||
|     LEDBlinker* me = (LEDBlinker*)Event_getTarget(ev); | ||||
|     LBSTATES oldState = me->state; | ||||
|     evIDT evid = Event_getId(ev); | ||||
|      | ||||
|     switch (me->state) | ||||
|     { | ||||
|         case ST_LBINIT: | ||||
|             if (evid == evLBInit) | ||||
|             { | ||||
|                 me->state = ST_LBOFF; | ||||
|             } | ||||
|             break; | ||||
|         case ST_LBOFF: | ||||
|             if (evid == evLBTMOn) | ||||
|             { | ||||
|                 me->state = ST_LBON; | ||||
|             } | ||||
|             break; | ||||
|         case ST_LBON: | ||||
|             if (evid == evLBTMOff) | ||||
|             { | ||||
|                 me->state = ST_LBOFF; | ||||
|             } | ||||
|             break; | ||||
|         default: | ||||
|             break; | ||||
|     } | ||||
|      | ||||
|     if (oldState != me->state) | ||||
|     { | ||||
|         switch (me->state) | ||||
|         { | ||||
|             case ST_LBINIT: | ||||
|                 break; | ||||
|             case ST_LBOFF: | ||||
|                 LED_off(l()); | ||||
|                 LED_off(l2()); | ||||
|                 POST(me, &LEDBlinker_processEvent, evLBTMOn,TMOFF,0); | ||||
|                 break; | ||||
|             case ST_LBON: | ||||
|                 LED_on(l()); | ||||
|                 LED_on(l2()); | ||||
|                 POST(me, &LEDBlinker_processEvent, evLBTMOff,TMON,0); | ||||
|                 break; | ||||
|             default: | ||||
|                 break; | ||||
|         }    | ||||
|         processed = true; | ||||
|     } | ||||
|     return processed; | ||||
| } | ||||
							
								
								
									
										42
									
								
								03-software/ch/kb28/blinkerProject/app/ledblinker.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								03-software/ch/kb28/blinkerProject/app/ledblinker.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| /*  | ||||
|  * File:   ledblinker.h | ||||
|  * Author: rim | ||||
|  * | ||||
|  * Created on May 14, 2023, 9:58 AM | ||||
|  */ | ||||
|  | ||||
| #ifndef LEDBLINKER_H | ||||
| #define	LEDBLINKER_H | ||||
|  | ||||
| #ifdef	__cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|      | ||||
| #include "../xf/xf.h" | ||||
|      | ||||
|     enum LBSTATES_ {ST_LBINIT, ST_LBOFF, ST_LBON}; | ||||
|     enum LBEVENTS_  {evLBInit=100, evLBTMOff, evLBTMOn}; | ||||
|     typedef enum LBSTATES_ LBSTATES; | ||||
|     typedef enum LBEVENTS_ LBEVENTS; | ||||
|      | ||||
|     struct LEDBlinker_ { | ||||
|         LBSTATES state; | ||||
|     }; | ||||
|      | ||||
|     typedef struct LEDBlinker_ LEDBlinker; | ||||
|   | ||||
| #define TMON 500 | ||||
| #define TMOFF 1000 | ||||
|      | ||||
|      | ||||
|     void LEDBlinker_init(LEDBlinker* me); | ||||
|      | ||||
|     void LEDBlinker_startBehaviour(LEDBlinker* me); | ||||
|     bool LEDBlinker_processEvent(Event* ev); | ||||
|  | ||||
| #ifdef	__cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #endif	/* LEDBLINKER_H */ | ||||
|  | ||||
							
								
								
									
										47
									
								
								03-software/ch/kb28/blinkerProject/app/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								03-software/ch/kb28/blinkerProject/app/main.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
|  | ||||
| #include "../mcc_generated_files/mcc.h" | ||||
| #include "../board/led/led.h" | ||||
| #include "../app/factory/factory.h" | ||||
| #include "../xf/xf.h" | ||||
|  | ||||
| bool test(Event* ev); | ||||
|  | ||||
| bool test(Event* ev) { | ||||
|     static bool on = true; | ||||
|     if (on == true){ | ||||
|         LED_on(l()); | ||||
|         on  =  false; | ||||
|     } else { | ||||
|         LED_off(l()); | ||||
|         on = true; | ||||
|     } | ||||
|     POST(NULL,test, 2, 500, 0); | ||||
|     return true; | ||||
| } | ||||
|  | ||||
|  | ||||
| void main(void) | ||||
| { | ||||
|     // Initialize the device | ||||
|     SYSTEM_Initialize(); | ||||
|      | ||||
|     // Enable the Global Interrupts | ||||
|     INTERRUPT_GlobalInterruptEnable(); | ||||
|     //INTERRUPT_GlobalInterruptDisable(); | ||||
|     //INTERRUPT_PeripheralInterruptEnable(); | ||||
|     //INTERRUPT_PeripheralInterruptDisable(); | ||||
|  | ||||
|     XF_init(); | ||||
|  | ||||
|     Factory_init(); | ||||
|     Factory_build(); | ||||
|     Factory_start(); | ||||
|      | ||||
|     TMR0_SetInterruptHandler(XF_decrementAndQueueTimers); | ||||
|      | ||||
|      | ||||
|     while (1) | ||||
|     { | ||||
|         XF_executeOnce(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										92
									
								
								03-software/ch/kb28/blinkerProject/board/led/led.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								03-software/ch/kb28/blinkerProject/board/led/led.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| #include "led.h" | ||||
| #include "../../mcc_generated_files/pin_manager.h" | ||||
|  | ||||
| void LED_init(LED* me, uint8_t id) | ||||
| { | ||||
|     me->id = id; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * @brief Initialize the Driver | ||||
|  *  | ||||
|  */ | ||||
| void LED_initHW(LED* me) | ||||
| { | ||||
|     LED_off(me); | ||||
| } | ||||
|  | ||||
| void LED_on(LED* me) | ||||
| { | ||||
|     switch (me->id) | ||||
|     { | ||||
|         case 1: | ||||
|             OUTPUT1_SetHigh(); | ||||
|         break; | ||||
|         case 2: | ||||
|             OUTPUT2_SetHigh(); | ||||
|         break; | ||||
|         case 3: | ||||
|             OUTPUT3_SetHigh(); | ||||
|         break; | ||||
|         case 4: | ||||
|             OUTPUT4_SetHigh(); | ||||
|         break; | ||||
|         case 5: | ||||
|             OUTPUT5_SetHigh(); | ||||
|         break; | ||||
|         case 6: | ||||
|             OUTPUT6_SetHigh(); | ||||
|         break; | ||||
|         case 7: | ||||
|             OUTPUT7_SetHigh(); | ||||
|         break; | ||||
|         case 8: | ||||
|             OUTPUT8_SetHigh(); | ||||
|         break; | ||||
|         case 9: | ||||
|             OUTPUT9_SetHigh(); | ||||
|         break; | ||||
|         case 10: | ||||
|             OUTPUT10_SetHigh(); | ||||
|         break;     | ||||
|     } | ||||
|        | ||||
| } | ||||
|  | ||||
| void LED_off(LED* me) | ||||
| { | ||||
|     switch (me->id) | ||||
|     { | ||||
|         case 1: | ||||
|             OUTPUT1_SetLow(); | ||||
|         break; | ||||
|         case 2: | ||||
|             OUTPUT2_SetLow(); | ||||
|         break; | ||||
|         case 3: | ||||
|             OUTPUT3_SetLow(); | ||||
|         break; | ||||
|         case 4: | ||||
|             OUTPUT4_SetLow(); | ||||
|         break; | ||||
|         case 5: | ||||
|             OUTPUT5_SetLow(); | ||||
|         break; | ||||
|         case 6: | ||||
|             OUTPUT6_SetLow(); | ||||
|         break; | ||||
|         case 7: | ||||
|             OUTPUT7_SetLow(); | ||||
|         break; | ||||
|         case 8: | ||||
|             OUTPUT8_SetLow(); | ||||
|         break; | ||||
|         case 9: | ||||
|             OUTPUT9_SetLow(); | ||||
|         break; | ||||
|         case 10: | ||||
|             OUTPUT10_SetLow(); | ||||
|         break;     | ||||
|     }             | ||||
| } | ||||
|  | ||||
							
								
								
									
										26
									
								
								03-software/ch/kb28/blinkerProject/board/led/led.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								03-software/ch/kb28/blinkerProject/board/led/led.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| /*  | ||||
|  * File:   led.h | ||||
|  * Author: rim | ||||
|  * | ||||
|  * Created on May 15, 2023, 7:56 AM | ||||
|  */ | ||||
|  | ||||
| #ifndef LED_H | ||||
| #define	LED_H | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| struct LED_ | ||||
| { | ||||
|     uint8_t id; | ||||
| }; | ||||
|  | ||||
| typedef struct LED_ LED; | ||||
|  | ||||
| void LED_init(LED* me, uint8_t id); | ||||
| void LED_initHW(LED* me); | ||||
| void LED_on(LED* me); | ||||
| void LED_off(LED* me); | ||||
|  | ||||
| #endif	/* LED_H */ | ||||
|  | ||||
| @@ -0,0 +1,117 @@ | ||||
| /** | ||||
|   @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File | ||||
|  | ||||
|   @Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name: | ||||
|     mcc.c | ||||
|  | ||||
|   @Summary: | ||||
|     This is the device_config.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description: | ||||
|     This header file provides implementations for driver APIs for all modules selected in the GUI. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.00 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above or later | ||||
|         MPLAB             :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| // Configuration bits: selected in the GUI | ||||
|  | ||||
| // CONFIG1L | ||||
| #pragma config RETEN = ON    // VREG Sleep Enable bit->Enabled | ||||
| #pragma config INTOSCSEL = HIGH    // LF-INTOSC Low-power Enable bit->LF-INTOSC in High-power mode during Sleep | ||||
| #pragma config SOSCSEL = DIG    // SOSC Power Selection and mode Configuration bits->Digital (SCLKI) mode | ||||
| #pragma config XINST = OFF    // Extended Instruction Set->Disabled | ||||
|  | ||||
| // CONFIG1H | ||||
| #pragma config FOSC = INTIO2    // Oscillator->Internal RC oscillator | ||||
| #pragma config PLLCFG = OFF    // PLL x4 Enable bit->Disabled | ||||
| #pragma config FCMEN = OFF    // Fail-Safe Clock Monitor->Disabled | ||||
| #pragma config IESO = OFF    // Internal External Oscillator Switch Over Mode->Disabled | ||||
|  | ||||
| // CONFIG2L | ||||
| #pragma config PWRTEN = OFF    // Power Up Timer->Disabled | ||||
| #pragma config BOREN = SBORDIS    // Brown Out Detect->Enabled in hardware, SBOREN disabled | ||||
| #pragma config BORV = 3    // Brown-out Reset Voltage bits->1.8V | ||||
| #pragma config BORPWR = ZPBORMV    // BORMV Power level->ZPBORMV instead of BORMV is selected | ||||
|  | ||||
| // CONFIG2H | ||||
| #pragma config WDTEN = OFF    // Watchdog Timer->WDT disabled in hardware; SWDTEN bit disabled | ||||
| #pragma config WDTPS = 1048576    // Watchdog Postscaler->1:1048576 | ||||
|  | ||||
| // CONFIG3L | ||||
| #pragma config RTCOSC = SOSCREF    // RTCC Clock Select->RTCC uses SOSC | ||||
| #pragma config EASHFT = ON    // External Address Shift bit->Address shifting enabled | ||||
| #pragma config ABW = MM    // Address Bus Width Select bits->8-bit address bus | ||||
| #pragma config BW = 16    // Data Bus Width->16-bit external bus mode | ||||
| #pragma config WAIT = OFF    // External Bus Wait->Disabled | ||||
|  | ||||
| // CONFIG3H | ||||
| #pragma config CCP2MX = PORTC    // CCP2 Mux->RC1 | ||||
| #pragma config ECCPMX = PORTE    // ECCP Mux->Enhanced CCP1/3 [P1B/P1C/P3B/P3C] muxed with RE6/RE5/RE4/RE3 | ||||
| #pragma config MSSPMSK = MSK7    // MSSP address masking->7 Bit address masking mode | ||||
| #pragma config MCLRE = ON    // Master Clear Enable->MCLR Enabled, RG5 Disabled | ||||
|  | ||||
| // CONFIG4L | ||||
| #pragma config STVREN = ON    // Stack Overflow Reset->Enabled | ||||
| #pragma config BBSIZ = BB2K    // Boot Block Size->2K word Boot Block size | ||||
| #pragma config DEBUG = OFF    // Background Debug->Disabled | ||||
|  | ||||
| // CONFIG5L | ||||
| #pragma config CP0 = OFF    // Code Protect 00800-03FFF->Disabled | ||||
| #pragma config CP1 = OFF    // Code Protect 04000-07FFF->Disabled | ||||
| #pragma config CP2 = OFF    // Code Protect 08000-0BFFF->Disabled | ||||
| #pragma config CP3 = OFF    // Code Protect 0C000-0FFFF->Disabled | ||||
|  | ||||
| // CONFIG5H | ||||
| #pragma config CPB = OFF    // Code Protect Boot->Disabled | ||||
| #pragma config CPD = OFF    // Data EE Read Protect->Disabled | ||||
|  | ||||
| // CONFIG6L | ||||
| #pragma config WRT0 = OFF    // Table Write Protect 00800-03FFF->Disabled | ||||
| #pragma config WRT1 = OFF    // Table Write Protect 04000-07FFF->Disabled | ||||
| #pragma config WRT2 = OFF    // Table Write Protect 08000-0BFFF->Disabled | ||||
| #pragma config WRT3 = OFF    // Table Write Protect 0C000-0FFFF->Disabled | ||||
|  | ||||
| // CONFIG6H | ||||
| #pragma config WRTC = OFF    // Config. Write Protect->Disabled | ||||
| #pragma config WRTB = OFF    // Table Write Protect Boot->Disabled | ||||
| #pragma config WRTD = OFF    // Data EE Write Protect->Disabled | ||||
|  | ||||
| // CONFIG7L | ||||
| #pragma config EBRT0 = OFF    // Table Read Protect 00800-03FFF->Disabled | ||||
| #pragma config EBRT1 = OFF    // Table Read Protect 04000-07FFF->Disabled | ||||
| #pragma config EBRT2 = OFF    // Table Read Protect 08000-0BFFF->Disabled | ||||
| #pragma config EBRT3 = OFF    // Table Read Protect 0C000-0FFFF->Disabled | ||||
|  | ||||
| // CONFIG7H | ||||
| #pragma config EBRTB = OFF    // Table Read Protect Boot->Disabled | ||||
| @@ -0,0 +1,55 @@ | ||||
| /** | ||||
|   @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File | ||||
|  | ||||
|   @Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name: | ||||
|     mcc.c | ||||
|  | ||||
|   @Summary: | ||||
|     This is the device_config.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description: | ||||
|     This header file provides implementations for driver APIs for all modules selected in the GUI. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.00 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above or later | ||||
|         MPLAB             :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef DEVICE_CONFIG_H | ||||
| #define	DEVICE_CONFIG_H | ||||
|  | ||||
| #define _XTAL_FREQ 64000000 | ||||
|  | ||||
| #endif	/* DEVICE_CONFIG_H */ | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
| @@ -0,0 +1,72 @@ | ||||
| /** | ||||
|   Generated Interrupt Manager Source File | ||||
|  | ||||
|   @Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name: | ||||
|     interrupt_manager.c | ||||
|  | ||||
|   @Summary: | ||||
|     This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description: | ||||
|     This header file provides implementations for global interrupt handling. | ||||
|     For individual peripheral handlers please see the peripheral driver for | ||||
|     all modules selected in the GUI. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.04 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above or later | ||||
|         MPLAB 	          :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #include "interrupt_manager.h" | ||||
| #include "mcc.h" | ||||
|  | ||||
| void  INTERRUPT_Initialize (void) | ||||
| { | ||||
|     // Disable Interrupt Priority Vectors (16CXXX Compatibility Mode) | ||||
|     RCONbits.IPEN = 0; | ||||
| } | ||||
|  | ||||
| void __interrupt() INTERRUPT_InterruptManager (void) | ||||
| { | ||||
|     // interrupt handler | ||||
|     if(INTCONbits.TMR0IE == 1 && INTCONbits.TMR0IF == 1) | ||||
|     { | ||||
|         TMR0_ISR(); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         //Unhandled Interrupt | ||||
|     } | ||||
| } | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
| @@ -0,0 +1,115 @@ | ||||
| /** | ||||
|   Generated Interrupt Manager Header File | ||||
|  | ||||
|   @Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name: | ||||
|     interrupt_manager.h | ||||
|  | ||||
|   @Summary: | ||||
|     This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description: | ||||
|     This header file provides implementations for global interrupt handling. | ||||
|     For individual peripheral handlers please see the peripheral driver for | ||||
|     all modules selected in the GUI. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.03 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above or later | ||||
|         MPLAB 	          :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef INTERRUPT_MANAGER_H | ||||
| #define INTERRUPT_MANAGER_H | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     This macro will enable global interrupts. | ||||
|  * @Example | ||||
|     INTERRUPT_GlobalInterruptEnable(); | ||||
|  */ | ||||
| #define INTERRUPT_GlobalInterruptEnable() (INTCONbits.GIE = 1) | ||||
|  | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     This macro will disable global interrupts. | ||||
|  * @Example | ||||
|     INTERRUPT_GlobalInterruptDisable(); | ||||
|  */ | ||||
| #define INTERRUPT_GlobalInterruptDisable() (INTCONbits.GIE = 0) | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     This macro will enable peripheral interrupts. | ||||
|  * @Example | ||||
|     INTERRUPT_PeripheralInterruptEnable(); | ||||
|  */ | ||||
| #define INTERRUPT_PeripheralInterruptEnable() (INTCONbits.PEIE = 1) | ||||
|  | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     This macro will disable peripheral interrupts. | ||||
|  * @Example | ||||
|     INTERRUPT_PeripheralInterruptDisable(); | ||||
|  */ | ||||
| #define INTERRUPT_PeripheralInterruptDisable() (INTCONbits.PEIE = 0) | ||||
|  | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     Initializes PIC18 peripheral interrupt priorities; enables/disables priority vectors | ||||
|  * @Example | ||||
|     INTERRUPT_Initialize(); | ||||
|  */ | ||||
| void INTERRUPT_Initialize (void); | ||||
|  | ||||
| #endif  // INTERRUPT_MANAGER_H | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
							
								
								
									
										74
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/mcc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/mcc.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| /** | ||||
|   @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File | ||||
|  | ||||
|   @Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name: | ||||
|     mcc.c | ||||
|  | ||||
|   @Summary: | ||||
|     This is the mcc.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description: | ||||
|     This header file provides implementations for driver APIs for all modules selected in the GUI. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.00 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above or later | ||||
|         MPLAB             :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #include "mcc.h" | ||||
|  | ||||
|  | ||||
| void SYSTEM_Initialize(void) | ||||
| { | ||||
|  | ||||
|     INTERRUPT_Initialize(); | ||||
|     PIN_MANAGER_Initialize(); | ||||
|     OSCILLATOR_Initialize(); | ||||
|     TMR0_Initialize(); | ||||
| } | ||||
|  | ||||
| void OSCILLATOR_Initialize(void) | ||||
| { | ||||
|     // SCS FOSC; IDLEN disabled; IRCF 16MHz_HF;  | ||||
|     OSCCON = 0x70; | ||||
|     // SOSCGO disabled; MFIOSEL disabled;  | ||||
|     OSCCON2 = 0x00; | ||||
|     // INTSRC INTRC; PLLEN enabled; TUN 0;  | ||||
|     OSCTUNE = 0x40; | ||||
|     // ROSEL System Clock(FOSC); ROON disabled; ROSSLP Disabled in Sleep mode; RODIV Fosc;  | ||||
|     REFOCON = 0x00; | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
							
								
								
									
										89
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/mcc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/mcc.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,89 @@ | ||||
| /** | ||||
|   @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File | ||||
|  | ||||
|   @Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name: | ||||
|     mcc.h | ||||
|  | ||||
|   @Summary: | ||||
|     This is the mcc.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description: | ||||
|     This header file provides implementations for driver APIs for all modules selected in the GUI. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.00 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above or later | ||||
|         MPLAB             :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef MCC_H | ||||
| #define	MCC_H | ||||
| #include  <xc.h> | ||||
| #include "device_config.h" | ||||
| #include "pin_manager.h" | ||||
| #include <stdint.h> | ||||
| #include <stdbool.h> | ||||
| #include <conio.h> | ||||
| #include "interrupt_manager.h" | ||||
| #include "tmr0.h" | ||||
|  | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     Initializes the device to the default states configured in the | ||||
|  *                  MCC GUI | ||||
|  * @Example | ||||
|     SYSTEM_Initialize(void); | ||||
|  */ | ||||
| void SYSTEM_Initialize(void); | ||||
|  | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     Initializes the oscillator to the default states configured in the | ||||
|  *                  MCC GUI | ||||
|  * @Example | ||||
|     OSCILLATOR_Initialize(void); | ||||
|  */ | ||||
| void OSCILLATOR_Initialize(void); | ||||
|  | ||||
| #endif	/* MCC_H */ | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
| @@ -0,0 +1,109 @@ | ||||
| /** | ||||
|   Generated Pin Manager File | ||||
|  | ||||
|   Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   File Name: | ||||
|     pin_manager.c | ||||
|  | ||||
|   Summary: | ||||
|     This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   Description: | ||||
|     This header file provides implementations for pin APIs for all pins selected in the GUI. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.11 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above | ||||
|         MPLAB             :  MPLAB X 6.00 | ||||
|  | ||||
|     Copyright (c) 2013 - 2015 released Microchip Technology Inc.  All rights reserved. | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #include "pin_manager.h" | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| void PIN_MANAGER_Initialize(void) | ||||
| { | ||||
|     /** | ||||
|     LATx registers | ||||
|     */ | ||||
|     LATE = 0x00; | ||||
|     LATD = 0x00; | ||||
|     LATA = 0x00; | ||||
|     LATF = 0x00; | ||||
|     LATB = 0x00; | ||||
|     LATG = 0x00; | ||||
|     LATC = 0x00; | ||||
|     LATH = 0x00; | ||||
|  | ||||
|     /** | ||||
|     TRISx registers | ||||
|     */ | ||||
|     TRISE = 0xFF; | ||||
|     TRISF = 0xFE; | ||||
|     TRISA = 0xFF; | ||||
|     TRISG = 0x07; | ||||
|     TRISB = 0xFF; | ||||
|     TRISH = 0x00; | ||||
|     TRISC = 0xFF; | ||||
|     TRISD = 0xFF; | ||||
|  | ||||
|     /** | ||||
|     ANSELx registers | ||||
|     */ | ||||
|     ANCON0 = 0xFF; | ||||
|     ANCON1 = 0x0F; | ||||
|     ANCON2 = 0x0C; | ||||
|  | ||||
|     /** | ||||
|     WPUx registers | ||||
|     */ | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     | ||||
|      | ||||
| } | ||||
|    | ||||
| void PIN_MANAGER_IOC(void) | ||||
| {    | ||||
| 	// Clear global Interrupt-On-Change flag | ||||
|     INTCONbits.RBIF = 0; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
| @@ -0,0 +1,270 @@ | ||||
| /** | ||||
|   @Generated Pin Manager Header File | ||||
|  | ||||
|   @Company: | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name: | ||||
|     pin_manager.h | ||||
|  | ||||
|   @Summary: | ||||
|     This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description | ||||
|     This header file provides APIs for driver for . | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.11 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above | ||||
|         MPLAB 	          :  MPLAB X 6.00	 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef PIN_MANAGER_H | ||||
| #define PIN_MANAGER_H | ||||
|  | ||||
| /** | ||||
|   Section: Included Files | ||||
| */ | ||||
|  | ||||
| #include <xc.h> | ||||
|  | ||||
| #define INPUT   1 | ||||
| #define OUTPUT  0 | ||||
|  | ||||
| #define HIGH    1 | ||||
| #define LOW     0 | ||||
|  | ||||
| #define ANALOG      1 | ||||
| #define DIGITAL     0 | ||||
|  | ||||
| #define PULL_UP_ENABLED      1 | ||||
| #define PULL_UP_DISABLED     0 | ||||
|  | ||||
| // get/set INPUT1 aliases | ||||
| #define INPUT1_TRIS                 TRISBbits.TRISB0 | ||||
| #define INPUT1_LAT                  LATBbits.LATB0 | ||||
| #define INPUT1_PORT                 PORTBbits.RB0 | ||||
| #define INPUT1_SetHigh()            do { LATBbits.LATB0 = 1; } while(0) | ||||
| #define INPUT1_SetLow()             do { LATBbits.LATB0 = 0; } while(0) | ||||
| #define INPUT1_Toggle()             do { LATBbits.LATB0 = ~LATBbits.LATB0; } while(0) | ||||
| #define INPUT1_GetValue()           PORTBbits.RB0 | ||||
| #define INPUT1_SetDigitalInput()    do { TRISBbits.TRISB0 = 1; } while(0) | ||||
| #define INPUT1_SetDigitalOutput()   do { TRISBbits.TRISB0 = 0; } while(0) | ||||
|  | ||||
| // get/set INPUT2 aliases | ||||
| #define INPUT2_TRIS                 TRISBbits.TRISB1 | ||||
| #define INPUT2_LAT                  LATBbits.LATB1 | ||||
| #define INPUT2_PORT                 PORTBbits.RB1 | ||||
| #define INPUT2_SetHigh()            do { LATBbits.LATB1 = 1; } while(0) | ||||
| #define INPUT2_SetLow()             do { LATBbits.LATB1 = 0; } while(0) | ||||
| #define INPUT2_Toggle()             do { LATBbits.LATB1 = ~LATBbits.LATB1; } while(0) | ||||
| #define INPUT2_GetValue()           PORTBbits.RB1 | ||||
| #define INPUT2_SetDigitalInput()    do { TRISBbits.TRISB1 = 1; } while(0) | ||||
| #define INPUT2_SetDigitalOutput()   do { TRISBbits.TRISB1 = 0; } while(0) | ||||
|  | ||||
| // get/set INPUT3 aliases | ||||
| #define INPUT3_TRIS                 TRISBbits.TRISB4 | ||||
| #define INPUT3_LAT                  LATBbits.LATB4 | ||||
| #define INPUT3_PORT                 PORTBbits.RB4 | ||||
| #define INPUT3_SetHigh()            do { LATBbits.LATB4 = 1; } while(0) | ||||
| #define INPUT3_SetLow()             do { LATBbits.LATB4 = 0; } while(0) | ||||
| #define INPUT3_Toggle()             do { LATBbits.LATB4 = ~LATBbits.LATB4; } while(0) | ||||
| #define INPUT3_GetValue()           PORTBbits.RB4 | ||||
| #define INPUT3_SetDigitalInput()    do { TRISBbits.TRISB4 = 1; } while(0) | ||||
| #define INPUT3_SetDigitalOutput()   do { TRISBbits.TRISB4 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT9 aliases | ||||
| #define OUTPUT9_TRIS                 TRISGbits.TRISG3 | ||||
| #define OUTPUT9_LAT                  LATGbits.LATG3 | ||||
| #define OUTPUT9_PORT                 PORTGbits.RG3 | ||||
| #define OUTPUT9_ANS                  ANCON2bits.ANSEL17 | ||||
| #define OUTPUT9_SetHigh()            do { LATGbits.LATG3 = 1; } while(0) | ||||
| #define OUTPUT9_SetLow()             do { LATGbits.LATG3 = 0; } while(0) | ||||
| #define OUTPUT9_Toggle()             do { LATGbits.LATG3 = ~LATGbits.LATG3; } while(0) | ||||
| #define OUTPUT9_GetValue()           PORTGbits.RG3 | ||||
| #define OUTPUT9_SetDigitalInput()    do { TRISGbits.TRISG3 = 1; } while(0) | ||||
| #define OUTPUT9_SetDigitalOutput()   do { TRISGbits.TRISG3 = 0; } while(0) | ||||
| #define OUTPUT9_SetAnalogMode()      do { ANCON2bits.ANSEL17 = 1; } while(0) | ||||
| #define OUTPUT9_SetDigitalMode()     do { ANCON2bits.ANSEL17 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT10 aliases | ||||
| #define OUTPUT10_TRIS                 TRISGbits.TRISG4 | ||||
| #define OUTPUT10_LAT                  LATGbits.LATG4 | ||||
| #define OUTPUT10_PORT                 PORTGbits.RG4 | ||||
| #define OUTPUT10_ANS                  ANCON2bits.ANSEL16 | ||||
| #define OUTPUT10_SetHigh()            do { LATGbits.LATG4 = 1; } while(0) | ||||
| #define OUTPUT10_SetLow()             do { LATGbits.LATG4 = 0; } while(0) | ||||
| #define OUTPUT10_Toggle()             do { LATGbits.LATG4 = ~LATGbits.LATG4; } while(0) | ||||
| #define OUTPUT10_GetValue()           PORTGbits.RG4 | ||||
| #define OUTPUT10_SetDigitalInput()    do { TRISGbits.TRISG4 = 1; } while(0) | ||||
| #define OUTPUT10_SetDigitalOutput()   do { TRISGbits.TRISG4 = 0; } while(0) | ||||
| #define OUTPUT10_SetAnalogMode()      do { ANCON2bits.ANSEL16 = 1; } while(0) | ||||
| #define OUTPUT10_SetDigitalMode()     do { ANCON2bits.ANSEL16 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT1 aliases | ||||
| #define OUTPUT1_TRIS                 TRISHbits.TRISH0 | ||||
| #define OUTPUT1_LAT                  LATHbits.LATH0 | ||||
| #define OUTPUT1_PORT                 PORTHbits.RH0 | ||||
| #define OUTPUT1_ANS                  ANCON2bits.ANSEL23 | ||||
| #define OUTPUT1_SetHigh()            do { LATHbits.LATH0 = 1; } while(0) | ||||
| #define OUTPUT1_SetLow()             do { LATHbits.LATH0 = 0; } while(0) | ||||
| #define OUTPUT1_Toggle()             do { LATHbits.LATH0 = ~LATHbits.LATH0; } while(0) | ||||
| #define OUTPUT1_GetValue()           PORTHbits.RH0 | ||||
| #define OUTPUT1_SetDigitalInput()    do { TRISHbits.TRISH0 = 1; } while(0) | ||||
| #define OUTPUT1_SetDigitalOutput()   do { TRISHbits.TRISH0 = 0; } while(0) | ||||
| #define OUTPUT1_SetAnalogMode()      do { ANCON2bits.ANSEL23 = 1; } while(0) | ||||
| #define OUTPUT1_SetDigitalMode()     do { ANCON2bits.ANSEL23 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT2 aliases | ||||
| #define OUTPUT2_TRIS                 TRISHbits.TRISH1 | ||||
| #define OUTPUT2_LAT                  LATHbits.LATH1 | ||||
| #define OUTPUT2_PORT                 PORTHbits.RH1 | ||||
| #define OUTPUT2_ANS                  ANCON2bits.ANSEL22 | ||||
| #define OUTPUT2_SetHigh()            do { LATHbits.LATH1 = 1; } while(0) | ||||
| #define OUTPUT2_SetLow()             do { LATHbits.LATH1 = 0; } while(0) | ||||
| #define OUTPUT2_Toggle()             do { LATHbits.LATH1 = ~LATHbits.LATH1; } while(0) | ||||
| #define OUTPUT2_GetValue()           PORTHbits.RH1 | ||||
| #define OUTPUT2_SetDigitalInput()    do { TRISHbits.TRISH1 = 1; } while(0) | ||||
| #define OUTPUT2_SetDigitalOutput()   do { TRISHbits.TRISH1 = 0; } while(0) | ||||
| #define OUTPUT2_SetAnalogMode()      do { ANCON2bits.ANSEL22 = 1; } while(0) | ||||
| #define OUTPUT2_SetDigitalMode()     do { ANCON2bits.ANSEL22 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT3 aliases | ||||
| #define OUTPUT3_TRIS                 TRISHbits.TRISH2 | ||||
| #define OUTPUT3_LAT                  LATHbits.LATH2 | ||||
| #define OUTPUT3_PORT                 PORTHbits.RH2 | ||||
| #define OUTPUT3_ANS                  ANCON2bits.ANSEL21 | ||||
| #define OUTPUT3_SetHigh()            do { LATHbits.LATH2 = 1; } while(0) | ||||
| #define OUTPUT3_SetLow()             do { LATHbits.LATH2 = 0; } while(0) | ||||
| #define OUTPUT3_Toggle()             do { LATHbits.LATH2 = ~LATHbits.LATH2; } while(0) | ||||
| #define OUTPUT3_GetValue()           PORTHbits.RH2 | ||||
| #define OUTPUT3_SetDigitalInput()    do { TRISHbits.TRISH2 = 1; } while(0) | ||||
| #define OUTPUT3_SetDigitalOutput()   do { TRISHbits.TRISH2 = 0; } while(0) | ||||
| #define OUTPUT3_SetAnalogMode()      do { ANCON2bits.ANSEL21 = 1; } while(0) | ||||
| #define OUTPUT3_SetDigitalMode()     do { ANCON2bits.ANSEL21 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT4 aliases | ||||
| #define OUTPUT4_TRIS                 TRISHbits.TRISH3 | ||||
| #define OUTPUT4_LAT                  LATHbits.LATH3 | ||||
| #define OUTPUT4_PORT                 PORTHbits.RH3 | ||||
| #define OUTPUT4_ANS                  ANCON2bits.ANSEL20 | ||||
| #define OUTPUT4_SetHigh()            do { LATHbits.LATH3 = 1; } while(0) | ||||
| #define OUTPUT4_SetLow()             do { LATHbits.LATH3 = 0; } while(0) | ||||
| #define OUTPUT4_Toggle()             do { LATHbits.LATH3 = ~LATHbits.LATH3; } while(0) | ||||
| #define OUTPUT4_GetValue()           PORTHbits.RH3 | ||||
| #define OUTPUT4_SetDigitalInput()    do { TRISHbits.TRISH3 = 1; } while(0) | ||||
| #define OUTPUT4_SetDigitalOutput()   do { TRISHbits.TRISH3 = 0; } while(0) | ||||
| #define OUTPUT4_SetAnalogMode()      do { ANCON2bits.ANSEL20 = 1; } while(0) | ||||
| #define OUTPUT4_SetDigitalMode()     do { ANCON2bits.ANSEL20 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT5 aliases | ||||
| #define OUTPUT5_TRIS                 TRISHbits.TRISH4 | ||||
| #define OUTPUT5_LAT                  LATHbits.LATH4 | ||||
| #define OUTPUT5_PORT                 PORTHbits.RH4 | ||||
| #define OUTPUT5_ANS                  ANCON1bits.ANSEL12 | ||||
| #define OUTPUT5_SetHigh()            do { LATHbits.LATH4 = 1; } while(0) | ||||
| #define OUTPUT5_SetLow()             do { LATHbits.LATH4 = 0; } while(0) | ||||
| #define OUTPUT5_Toggle()             do { LATHbits.LATH4 = ~LATHbits.LATH4; } while(0) | ||||
| #define OUTPUT5_GetValue()           PORTHbits.RH4 | ||||
| #define OUTPUT5_SetDigitalInput()    do { TRISHbits.TRISH4 = 1; } while(0) | ||||
| #define OUTPUT5_SetDigitalOutput()   do { TRISHbits.TRISH4 = 0; } while(0) | ||||
| #define OUTPUT5_SetAnalogMode()      do { ANCON1bits.ANSEL12 = 1; } while(0) | ||||
| #define OUTPUT5_SetDigitalMode()     do { ANCON1bits.ANSEL12 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT6 aliases | ||||
| #define OUTPUT6_TRIS                 TRISHbits.TRISH5 | ||||
| #define OUTPUT6_LAT                  LATHbits.LATH5 | ||||
| #define OUTPUT6_PORT                 PORTHbits.RH5 | ||||
| #define OUTPUT6_ANS                  ANCON1bits.ANSEL13 | ||||
| #define OUTPUT6_SetHigh()            do { LATHbits.LATH5 = 1; } while(0) | ||||
| #define OUTPUT6_SetLow()             do { LATHbits.LATH5 = 0; } while(0) | ||||
| #define OUTPUT6_Toggle()             do { LATHbits.LATH5 = ~LATHbits.LATH5; } while(0) | ||||
| #define OUTPUT6_GetValue()           PORTHbits.RH5 | ||||
| #define OUTPUT6_SetDigitalInput()    do { TRISHbits.TRISH5 = 1; } while(0) | ||||
| #define OUTPUT6_SetDigitalOutput()   do { TRISHbits.TRISH5 = 0; } while(0) | ||||
| #define OUTPUT6_SetAnalogMode()      do { ANCON1bits.ANSEL13 = 1; } while(0) | ||||
| #define OUTPUT6_SetDigitalMode()     do { ANCON1bits.ANSEL13 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT7 aliases | ||||
| #define OUTPUT7_TRIS                 TRISHbits.TRISH6 | ||||
| #define OUTPUT7_LAT                  LATHbits.LATH6 | ||||
| #define OUTPUT7_PORT                 PORTHbits.RH6 | ||||
| #define OUTPUT7_ANS                  ANCON1bits.ANSEL14 | ||||
| #define OUTPUT7_SetHigh()            do { LATHbits.LATH6 = 1; } while(0) | ||||
| #define OUTPUT7_SetLow()             do { LATHbits.LATH6 = 0; } while(0) | ||||
| #define OUTPUT7_Toggle()             do { LATHbits.LATH6 = ~LATHbits.LATH6; } while(0) | ||||
| #define OUTPUT7_GetValue()           PORTHbits.RH6 | ||||
| #define OUTPUT7_SetDigitalInput()    do { TRISHbits.TRISH6 = 1; } while(0) | ||||
| #define OUTPUT7_SetDigitalOutput()   do { TRISHbits.TRISH6 = 0; } while(0) | ||||
| #define OUTPUT7_SetAnalogMode()      do { ANCON1bits.ANSEL14 = 1; } while(0) | ||||
| #define OUTPUT7_SetDigitalMode()     do { ANCON1bits.ANSEL14 = 0; } while(0) | ||||
|  | ||||
| // get/set OUTPUT8 aliases | ||||
| #define OUTPUT8_TRIS                 TRISHbits.TRISH7 | ||||
| #define OUTPUT8_LAT                  LATHbits.LATH7 | ||||
| #define OUTPUT8_PORT                 PORTHbits.RH7 | ||||
| #define OUTPUT8_ANS                  ANCON1bits.ANSEL15 | ||||
| #define OUTPUT8_SetHigh()            do { LATHbits.LATH7 = 1; } while(0) | ||||
| #define OUTPUT8_SetLow()             do { LATHbits.LATH7 = 0; } while(0) | ||||
| #define OUTPUT8_Toggle()             do { LATHbits.LATH7 = ~LATHbits.LATH7; } while(0) | ||||
| #define OUTPUT8_GetValue()           PORTHbits.RH7 | ||||
| #define OUTPUT8_SetDigitalInput()    do { TRISHbits.TRISH7 = 1; } while(0) | ||||
| #define OUTPUT8_SetDigitalOutput()   do { TRISHbits.TRISH7 = 0; } while(0) | ||||
| #define OUTPUT8_SetAnalogMode()      do { ANCON1bits.ANSEL15 = 1; } while(0) | ||||
| #define OUTPUT8_SetDigitalMode()     do { ANCON1bits.ANSEL15 = 0; } while(0) | ||||
|  | ||||
| /** | ||||
|    @Param | ||||
|     none | ||||
|    @Returns | ||||
|     none | ||||
|    @Description | ||||
|     GPIO and peripheral I/O initialization | ||||
|    @Example | ||||
|     PIN_MANAGER_Initialize(); | ||||
|  */ | ||||
| void PIN_MANAGER_Initialize (void); | ||||
|  | ||||
| /** | ||||
|  * @Param | ||||
|     none | ||||
|  * @Returns | ||||
|     none | ||||
|  * @Description | ||||
|     Interrupt on Change Handling routine | ||||
|  * @Example | ||||
|     PIN_MANAGER_IOC(); | ||||
|  */ | ||||
| void PIN_MANAGER_IOC(void); | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif // PIN_MANAGER_H | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
							
								
								
									
										167
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/tmr0.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/tmr0.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | ||||
| /** | ||||
|   TMR0 Generated Driver File | ||||
|  | ||||
|   @Company | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name | ||||
|     tmr0.c | ||||
|  | ||||
|   @Summary | ||||
|     This is the generated driver implementation file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description | ||||
|     This source file provides APIs for TMR0. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.01 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above | ||||
|         MPLAB 	          :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| /** | ||||
|   Section: Included Files | ||||
| */ | ||||
|  | ||||
| #include <xc.h> | ||||
| #include "tmr0.h" | ||||
|  | ||||
| /** | ||||
|   Section: Global Variables Definitions | ||||
| */ | ||||
|  | ||||
| void (*TMR0_InterruptHandler)(void); | ||||
|  | ||||
| volatile uint16_t timer0ReloadVal; | ||||
|  | ||||
| /** | ||||
|   Section: TMR0 APIs | ||||
| */ | ||||
|  | ||||
|  | ||||
| void TMR0_Initialize(void) | ||||
| { | ||||
|     // Set TMR0 to the options selected in the User Interface | ||||
|  | ||||
|     //Enable 16bit timer mode before assigning value to TMR0H | ||||
|     T0CONbits.T08BIT = 0; | ||||
|  | ||||
|     // TMR0H 99;  | ||||
|     TMR0H = 0x63; | ||||
|  | ||||
|     // TMR0L 191;  | ||||
|     TMR0L = 0xBF; | ||||
|  | ||||
| 	 | ||||
|     // Load TMR0 value to the 16-bit reload variable | ||||
|     timer0ReloadVal = (uint16_t)((TMR0H << 8) | TMR0L); | ||||
|  | ||||
|     // Clear Interrupt flag before enabling the interrupt | ||||
|     INTCONbits.TMR0IF = 0; | ||||
|  | ||||
|     // Enabling TMR0 interrupt. | ||||
|     INTCONbits.TMR0IE = 1; | ||||
|  | ||||
|     // Set Default Interrupt Handler | ||||
|     TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler); | ||||
|  | ||||
|     // T0PS 1:4; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA assigned;  | ||||
|     T0CON = 0x91; | ||||
| } | ||||
|  | ||||
| void TMR0_StartTimer(void) | ||||
| { | ||||
|     // Start the Timer by writing to TMR0ON bit | ||||
|     T0CONbits.TMR0ON = 1; | ||||
| } | ||||
|  | ||||
| void TMR0_StopTimer(void) | ||||
| { | ||||
|     // Stop the Timer by writing to TMR0ON bit | ||||
|     T0CONbits.TMR0ON = 0; | ||||
| } | ||||
|  | ||||
| uint16_t TMR0_ReadTimer(void) | ||||
| { | ||||
|     uint16_t readVal; | ||||
|     uint8_t readValLow; | ||||
|     uint8_t readValHigh; | ||||
|  | ||||
|     readValLow  = TMR0L; | ||||
|     readValHigh = TMR0H; | ||||
|     readVal  = ((uint16_t)readValHigh << 8) + readValLow; | ||||
|  | ||||
|     return readVal; | ||||
| } | ||||
|  | ||||
| void TMR0_WriteTimer(uint16_t timerVal) | ||||
| { | ||||
|     // Write to the Timer0 register | ||||
|     TMR0H = timerVal >> 8; | ||||
|     TMR0L = (uint8_t) timerVal; | ||||
| } | ||||
|  | ||||
| void TMR0_Reload(void) | ||||
| { | ||||
|     // Write to the Timer0 register | ||||
|     TMR0H = timer0ReloadVal >> 8; | ||||
|     TMR0L = (uint8_t) timer0ReloadVal; | ||||
| } | ||||
|  | ||||
| void TMR0_ISR(void) | ||||
| { | ||||
|  | ||||
|     // clear the TMR0 interrupt flag | ||||
|     INTCONbits.TMR0IF = 0; | ||||
|  | ||||
|     // reload TMR0 | ||||
|     // Write to the Timer0 register | ||||
|     TMR0H = timer0ReloadVal >> 8; | ||||
|     TMR0L = (uint8_t) timer0ReloadVal; | ||||
|  | ||||
|     if(TMR0_InterruptHandler) | ||||
|     { | ||||
|         TMR0_InterruptHandler(); | ||||
|     } | ||||
|  | ||||
|     // add your TMR0 interrupt custom code | ||||
| } | ||||
|  | ||||
|  | ||||
| void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)){ | ||||
|     TMR0_InterruptHandler = InterruptHandler; | ||||
| } | ||||
|  | ||||
| void TMR0_DefaultInterruptHandler(void){ | ||||
|     // add your TMR0 interrupt custom code | ||||
|     // or set custom function using TMR0_SetInterruptHandler() | ||||
| } | ||||
|  | ||||
| /** | ||||
|   End of File | ||||
| */ | ||||
							
								
								
									
										356
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/tmr0.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										356
									
								
								03-software/ch/kb28/blinkerProject/mcc_generated_files/tmr0.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,356 @@ | ||||
| /** | ||||
|   TMR0 Generated Driver API Header File | ||||
|  | ||||
|   @Company | ||||
|     Microchip Technology Inc. | ||||
|  | ||||
|   @File Name | ||||
|     tmr0.h | ||||
|  | ||||
|   @Summary | ||||
|     This is the generated header file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||
|  | ||||
|   @Description | ||||
|     This header file provides APIs for TMR0. | ||||
|     Generation Information : | ||||
|         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||
|         Device            :  PIC18F86K22 | ||||
|         Driver Version    :  2.01 | ||||
|     The generated drivers are tested against the following: | ||||
|         Compiler          :  XC8 2.36 and above | ||||
|         MPLAB 	          :  MPLAB X 6.00 | ||||
| */ | ||||
|  | ||||
| /* | ||||
|     (c) 2018 Microchip Technology Inc. and its subsidiaries.  | ||||
|      | ||||
|     Subject to your compliance with these terms, you may use Microchip software and any  | ||||
|     derivatives exclusively with Microchip products. It is your responsibility to comply with third party  | ||||
|     license terms applicable to your use of third party software (including open source software) that  | ||||
|     may accompany Microchip software. | ||||
|      | ||||
|     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER  | ||||
|     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY  | ||||
|     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS  | ||||
|     FOR A PARTICULAR PURPOSE. | ||||
|      | ||||
|     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,  | ||||
|     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND  | ||||
|     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP  | ||||
|     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO  | ||||
|     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL  | ||||
|     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT  | ||||
|     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS  | ||||
|     SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef TMR0_H | ||||
| #define TMR0_H | ||||
|  | ||||
| /** | ||||
|   Section: Included Files | ||||
| */ | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include <stdbool.h> | ||||
|  | ||||
| #ifdef __cplusplus  // Provide C++ Compatibility | ||||
|  | ||||
|     extern "C" { | ||||
|  | ||||
| #endif | ||||
|  | ||||
|  | ||||
|  | ||||
| /** | ||||
|   Section: TMR0 APIs | ||||
| */ | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Initializes the TMR0. | ||||
|  | ||||
|   @Description | ||||
|     This function initializes the TMR0 Registers. | ||||
|     This function must be called before any other TMR0 function is called. | ||||
|  | ||||
|   @Preconditions | ||||
|     None | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
|  | ||||
|   @Comment | ||||
|      | ||||
| 	 | ||||
|   @Example | ||||
|     <code> | ||||
|     main() | ||||
|     { | ||||
|         // Initialize TMR0 module | ||||
|         TMR0_Initialize(); | ||||
|  | ||||
|         // Do something else... | ||||
|     } | ||||
|     </code> | ||||
| */ | ||||
| void TMR0_Initialize(void); | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     This function starts the TMR0. | ||||
|  | ||||
|   @Description | ||||
|     This function starts the TMR0 operation. | ||||
|     This function must be called after the initialization of TMR0. | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 before calling this function. | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
|  | ||||
|   @Example | ||||
|     <code> | ||||
|     // Initialize TMR0 module | ||||
|  | ||||
|     // Start TMR0 | ||||
|     TMR0_StartTimer(); | ||||
|  | ||||
|     // Do something else... | ||||
|     </code> | ||||
| */ | ||||
| void TMR0_StartTimer(void); | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     This function stops the TMR0. | ||||
|  | ||||
|   @Description | ||||
|     This function stops the TMR0 operation. | ||||
|     This function must be called after the start of TMR0. | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 before calling this function. | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
|  | ||||
|   @Example | ||||
|     <code> | ||||
|     // Initialize TMR0 module | ||||
|  | ||||
|     // Start TMR0 | ||||
|     TMR0_StartTimer(); | ||||
|  | ||||
|     // Do something else... | ||||
|  | ||||
|     // Stop TMR0; | ||||
|     TMR0_StopTimer(); | ||||
|     </code> | ||||
| */ | ||||
| void TMR0_StopTimer(void); | ||||
|  | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Reads the 16 bits TMR0 register value. | ||||
|  | ||||
|   @Description | ||||
|     This function reads the 16 bits TMR0 register value and return it. | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 before calling this function. | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     This function returns the 16 bits value of TMR0 register. | ||||
|  | ||||
|   @Example | ||||
|     <code> | ||||
|     // Initialize TMR0 module | ||||
|  | ||||
|     // Start TMR0 | ||||
|     TMR0_StartTimer(); | ||||
|  | ||||
|     // Read the current value of TMR0 | ||||
|     if(0 == TMR0_ReadTimer()) | ||||
|     { | ||||
|         // Do something else... | ||||
|  | ||||
|         // Reload the TMR value | ||||
|         TMR0_Reload(); | ||||
|     } | ||||
|     </code> | ||||
| */ | ||||
| uint16_t TMR0_ReadTimer(void); | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Writes the 16 bits value to TMR0 register. | ||||
|  | ||||
|   @Description | ||||
|     This function writes the 16 bits value to TMR0 register. | ||||
|     This function must be called after the initialization of TMR0. | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 before calling this function. | ||||
|  | ||||
|   @Param | ||||
|     timerVal - Value to write into TMR0 register. | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
|  | ||||
|   @Example | ||||
|     <code> | ||||
|     #define PERIOD 0x8000 | ||||
|     #define ZERO   0x0000 | ||||
|  | ||||
|     while(1) | ||||
|     { | ||||
|         //Read the TMR0 register | ||||
|         if(ZERO == TMR0_ReadTimer()) | ||||
|         { | ||||
|             // Do something else... | ||||
|  | ||||
|             // Write the TMR0 register | ||||
|             TMR0_WriteTimer(PERIOD); | ||||
|         } | ||||
|  | ||||
|         // Do something else... | ||||
|     } | ||||
|     </code> | ||||
| */ | ||||
| void TMR0_WriteTimer(uint16_t timerVal); | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Reload the 16 bits value to TMR0 register. | ||||
|  | ||||
|   @Description | ||||
|     This function reloads the 16 bit value to TMR0 register. | ||||
|     This function must be called to write initial value into TMR0 register. | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 before calling this function. | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
|  | ||||
|   @Example | ||||
|     <code> | ||||
|     while(1) | ||||
|     { | ||||
|         if(TMR0IF) | ||||
|         { | ||||
|             // Do something else... | ||||
|  | ||||
|             // clear the TMR0 interrupt flag | ||||
|             TMR0IF = 0; | ||||
|  | ||||
|             // Reload the initial value of TMR0 | ||||
|             TMR0_Reload(); | ||||
|         } | ||||
|     } | ||||
|     </code> | ||||
| */ | ||||
| void TMR0_Reload(void); | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Timer Interrupt Service Routine | ||||
|  | ||||
|   @Description | ||||
|     Timer Interrupt Service Routine is called by the Interrupt Manager. | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 module with interrupt before calling this isr. | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
|  */ | ||||
| void TMR0_ISR(void); | ||||
|  | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Set Timer Interrupt Handler | ||||
|  | ||||
|   @Description | ||||
|     This sets the function to be called during the ISR | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 module with interrupt before calling this. | ||||
|  | ||||
|   @Param | ||||
|     Address of function to be set | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
| */ | ||||
|  void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)); | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Timer Interrupt Handler | ||||
|  | ||||
|   @Description | ||||
|     This is a function pointer to the function that will be called during the ISR | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 module with interrupt before calling this isr. | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
| */ | ||||
| extern void (*TMR0_InterruptHandler)(void); | ||||
|  | ||||
| /** | ||||
|   @Summary | ||||
|     Default Timer Interrupt Handler | ||||
|  | ||||
|   @Description | ||||
|     This is the default Interrupt Handler function | ||||
|  | ||||
|   @Preconditions | ||||
|     Initialize  the TMR0 module with interrupt before calling this isr. | ||||
|  | ||||
|   @Param | ||||
|     None | ||||
|  | ||||
|   @Returns | ||||
|     None | ||||
| */ | ||||
| void TMR0_DefaultInterruptHandler(void); | ||||
|  | ||||
| #ifdef __cplusplus  // Provide C++ Compatibility | ||||
|  | ||||
|     } | ||||
|  | ||||
| #endif | ||||
|  | ||||
| #endif // TMR0_H | ||||
| /** | ||||
|  End of File | ||||
| */ | ||||
							
								
								
									
										61
									
								
								03-software/ch/kb28/blinkerProject/xf/event.c
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										61
									
								
								03-software/ch/kb28/blinkerProject/xf/event.c
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| #include "event.h" | ||||
| #define NULL ((void*)(0)) | ||||
|  | ||||
| void Event_init(struct Event_* me) | ||||
| { | ||||
|     me->id = NULLEVENT; | ||||
|     me->delay = 0; | ||||
|     me->target = NULL; | ||||
|     me->data = 0x0; | ||||
|     me->processEvent = NULL; | ||||
| } | ||||
|  | ||||
| void Event_setData(Event* me, int64_t data) | ||||
| { | ||||
|     me->data = data; | ||||
| } | ||||
|  | ||||
| int64_t Event_getData(Event* me)  | ||||
| { | ||||
|     return me->data; | ||||
| } | ||||
|  | ||||
| void Event_setPE(Event* me, processEventT processEvent) | ||||
| { | ||||
|     me->processEvent = processEvent; | ||||
| } | ||||
|  | ||||
| void Event_setTarget(Event* me, void* target) | ||||
| { | ||||
|     me->target = target; | ||||
| } | ||||
|  | ||||
| processEventT Event_getPE(Event* me) | ||||
| { | ||||
|     return me->processEvent; | ||||
| } | ||||
|  | ||||
| void* Event_getTarget(Event* me) | ||||
| { | ||||
|     return me->target; | ||||
| } | ||||
|  | ||||
| void Event_setId(Event* me, evIDT eventID) | ||||
| { | ||||
|     me->id = eventID; | ||||
| } | ||||
|  | ||||
| evIDT Event_getId(Event* me) | ||||
| { | ||||
|     return me->id; | ||||
| } | ||||
|  | ||||
| void Event_setDelay(Event* me, uint16_t delay) | ||||
| { | ||||
|     me->delay = delay; | ||||
| } | ||||
|  | ||||
| uint16_t Event_getDelay(Event* me) | ||||
| { | ||||
|     return me->delay; | ||||
| } | ||||
							
								
								
									
										35
									
								
								03-software/ch/kb28/blinkerProject/xf/event.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										35
									
								
								03-software/ch/kb28/blinkerProject/xf/event.h
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| #include <stdint.h> | ||||
| #include <stdbool.h> | ||||
| #include "ireactive.h" | ||||
|  | ||||
| #ifndef EVENT_ONCE | ||||
| #define EVENT_ONCE | ||||
|  | ||||
| typedef uint8_t evIDT; | ||||
| #define NULLEVENT 0         // no event | ||||
|  | ||||
| struct Event_ | ||||
| { | ||||
|     evIDT id; | ||||
|     processEventT processEvent; | ||||
|     void* target; | ||||
|     uint16_t delay; | ||||
|     int64_t data; | ||||
| }; | ||||
|  | ||||
| typedef struct Event_ Event; | ||||
|  | ||||
| //public methods | ||||
| void Event_init(Event* me); | ||||
| void Event_setTarget(Event* me, void* target); | ||||
| void Event_setPE(Event* me, processEventT processEvent); | ||||
| void* Event_getTarget(Event* me); | ||||
| processEventT Event_getPE(Event* me); | ||||
| void Event_setId(Event* me, evIDT eventID); | ||||
| evIDT Event_getId(Event* me); | ||||
| void Event_setDelay(Event* me, uint16_t delay); | ||||
| uint16_t Event_getDelay(Event* me); | ||||
| void Event_setData(Event* me, int64_t data); | ||||
| int64_t Event_getData(Event* me); | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										8
									
								
								03-software/ch/kb28/blinkerProject/xf/ireactive.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								03-software/ch/kb28/blinkerProject/xf/ireactive.h
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| #ifndef IREACTIVE_ONCE | ||||
| #define IREACTIVE_ONCE | ||||
|  | ||||
| struct Event_; | ||||
|  | ||||
| typedef bool (*processEventT)(struct Event_* ev); | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										292
									
								
								03-software/ch/kb28/blinkerProject/xf/xf.c
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										292
									
								
								03-software/ch/kb28/blinkerProject/xf/xf.c
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,292 @@ | ||||
| /******************************************************************************/ | ||||
| /* FILENAME	: xf.h                                                            */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* GOAL		  : Offers the femto XF functions (for PIC CPU)                     */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* AUTHOR   : Medard Rieder / Pascal Sartoretti                               */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* DATE:    : original (Medard Rieder 08.2011)                                */ | ||||
| /*            corrections & simplified (Pascal Sartoretti 06.2016)            */ | ||||
| /******************************************************************************/ | ||||
|  | ||||
| #include "xf.h" | ||||
| #include "../mcc_generated_files/mcc.h" | ||||
|  | ||||
| /* | ||||
|  * private methods of the XF | ||||
|  */ | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Push an event on the events queue                           */ | ||||
| /* INPUT        : ev - the event number (not 0)                               */ | ||||
| /*                inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : return false if the queue was full, else true               */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| bool XF_pushEvent(Event ev, bool inISR, TimerID* tmid); | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Pop an event on the events queue                            */ | ||||
| /* INPUT        : inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : return the next waiting event if any, else 0                */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| Event XF_popEvent(bool inISR); | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Post a timer in timers queue                                */ | ||||
| /* INPUT        : tm - time before event arrives                              */ | ||||
| /*                ev - event to post                                          */ | ||||
| /*                inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : return the timer Id used                                    */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| TimerID XF_scheduleTimer(Time tm, Event ev, bool inISR); | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Switch of the interrupts                                    */ | ||||
| /* INPUT        : inISR - (true if called in an ISR, else f                   */ | ||||
| /* OUTPUT       : none                                                        */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| static void ENTERCRITICAL(bool inISR); | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Switch on the interrupts                                    */ | ||||
| /* INPUT        : inISR - (true if called in an ISR, else f                   */ | ||||
| /* OUTPUT       : none                                                        */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| static void LEAVECRITICAL(bool inISR); | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * the XF instance | ||||
|  */ | ||||
| XF theXF;      // really the XF | ||||
|  | ||||
|  | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Init the XF structure                                       */ | ||||
| /* INPUT        : -                                                           */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : Have to be called once                                      */ | ||||
| /******************************************************************************/ | ||||
| void XF_init() | ||||
| { | ||||
|     int i; | ||||
|     for (i=0; i<MAXEVENT; i++) | ||||
|     { | ||||
|         Event_init(&(theXF.eventQueue[i])); | ||||
|     } | ||||
|  | ||||
|     for (i=0; i<MAXTIMER; i++) | ||||
|     { | ||||
|         theXF.timerList[i].tm = NULLTIMER; | ||||
|         Event_init(&(theXF.timerList[i].ev)); | ||||
|     } | ||||
|     theXF.in = 0; | ||||
|     theXF.out = 0; | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Push an event on the events queue                           */ | ||||
| /* INPUT        : ev - the event number (not 0)                               */ | ||||
| /*                inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : return false if the queue was full, else true               */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| bool XF_pushEvent(Event ev, bool inISR, TimerID* tmid) | ||||
| { | ||||
|     uint8_t temp; | ||||
|     Time tm; | ||||
|     tm = Event_getDelay(&ev);  | ||||
|     if ( tm > 0) | ||||
|     { | ||||
|         Event_setDelay(&ev,0); | ||||
|         *tmid = XF_scheduleTimer(tm, ev, inISR); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         ENTERCRITICAL(inISR); | ||||
|  | ||||
|         temp = (theXF.in+1) % (uint8_t)(sizeof(theXF.eventQueue) / sizeof(Event)); | ||||
|         if(temp == theXF.out) | ||||
|         {       | ||||
|           LEAVECRITICAL(inISR); | ||||
|           return false; | ||||
|         } | ||||
|         theXF.eventQueue[theXF.in] = ev; | ||||
|         theXF.in = temp; | ||||
|         LEAVECRITICAL(inISR); | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Pop an event on the events queue                            */ | ||||
| /* INPUT        : inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : return the next waiting event if any, else 0                */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| Event XF_popEvent(bool inISR) | ||||
| { | ||||
|     Event ev; | ||||
|     ev.id = NULLEVENT; | ||||
|     ev.target = NULL; | ||||
|     ev.processEvent = NULL; | ||||
|  | ||||
|     ENTERCRITICAL(inISR); | ||||
|     if(theXF.in == theXF.out) | ||||
|     { | ||||
|       LEAVECRITICAL(inISR); | ||||
|       return ev; | ||||
|     } | ||||
|     ev = theXF.eventQueue[theXF.out]; | ||||
|     theXF.out = (theXF.out + 1)%(uint8_t)(sizeof(theXF.eventQueue) / sizeof(Event)); | ||||
|     LEAVECRITICAL(inISR); | ||||
|     return ev;     | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Post a timer in timers queue                                */ | ||||
| /* INPUT        : tm - time before event arrives                              */ | ||||
| /*                ev - event to post                                          */ | ||||
| /*                inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : return the timer Id used                                    */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| TimerID XF_scheduleTimer(Time tm, Event ev, bool inISR) | ||||
| { | ||||
|     uint8_t i; | ||||
|  | ||||
|     ENTERCRITICAL(inISR); | ||||
|     for (i=0; i<MAXTIMER; i++) | ||||
|     { | ||||
|         if (theXF.timerList[i].ev.id == NULLEVENT) | ||||
|         { | ||||
|             theXF.timerList[i].tm = tm; | ||||
|             theXF.timerList[i].ev = ev; | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     //here you could react | ||||
|     //if timerlist is full | ||||
|  | ||||
|     LEAVECRITICAL(inISR); | ||||
|     return i; | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Remove a timer in timers queue                              */ | ||||
| /* INPUT        : id - the timer id to remove                                 */ | ||||
| /*                inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| void XF_unscheduleTimer(TimerID id, bool inISR) | ||||
| { | ||||
|     ENTERCRITICAL(inISR); | ||||
|     theXF.timerList[id].tm = NULLTIMER; | ||||
|     Event_init(&(theXF.timerList[id].ev));  | ||||
|     LEAVECRITICAL(inISR); | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Decrement timers to post events if time elapsed             */ | ||||
| /* INPUT        : -                                                           */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : This function has to be called from the timer ISR           */ | ||||
| /******************************************************************************/ | ||||
| void XF_decrementAndQueueTimers() | ||||
| { | ||||
|     uint8_t i; | ||||
|     for (i=0; i<MAXTIMER; i++) | ||||
|     { | ||||
|         if (theXF.timerList[i].ev.id != NULLEVENT) | ||||
|         { | ||||
|             theXF.timerList[i].tm-=TICKINTERVAL; | ||||
|             if (theXF.timerList[i].tm ==0) | ||||
|             { | ||||
|                 TimerID dummy; | ||||
|                 if (XF_pushEvent(theXF.timerList[i].ev, true, &dummy) == true) | ||||
|                 {   | ||||
|                   XF_unscheduleTimer(i, true); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                   theXF.timerList[i].tm=1; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     //here you could use done to react | ||||
|     //if timerID was not found (done == 0) | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Lock interrupts if not in ISR                               */ | ||||
| /* INPUT        : -                                                           */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| static void ENTERCRITICAL(bool inISR) | ||||
| { | ||||
|     if (inISR == false) | ||||
|     { | ||||
|       //GIE = 0; | ||||
|       INTERRUPT_GlobalInterruptDisable(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Unlock interrupts if not in ISR                             */ | ||||
| /* INPUT        : -                                                           */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| static void LEAVECRITICAL(bool inISR) | ||||
| { | ||||
|     if (inISR == false) | ||||
|     { | ||||
|       //GIE = 1; | ||||
|      INTERRUPT_GlobalInterruptEnable();    | ||||
|     } | ||||
| } | ||||
|  | ||||
| TimerID POST(void* target, processEventT processEvent, uint8_t id, Time delay , int64_t data) | ||||
| { | ||||
|     TimerID tmid = MAXTIMER;  //this is to say that no timer has been scheduled | ||||
|                               //is a timer has been scheduled, the ID will be  | ||||
|                               //from 0 to MAXTIMER-1 | ||||
|     Event ev; | ||||
|     Event_init(&ev); | ||||
|     Event_setTarget(&ev,target); | ||||
|     Event_setPE(&ev,processEvent); | ||||
|     Event_setId(&ev,id); | ||||
|     Event_setDelay(&ev,delay); | ||||
|     Event_setData(&ev,data); | ||||
|     XF_pushEvent(ev,false,&tmid); | ||||
|     return tmid; | ||||
| } | ||||
|  | ||||
| void XF_executeOnce() | ||||
| { | ||||
|     Event ev = XF_popEvent(false); | ||||
|     //if this event is valid | ||||
|     if (ev.id != NULLEVENT) | ||||
|     { | ||||
|         //if this event has a valid target | ||||
|         //if (ev.target != NULL) | ||||
|         //{ | ||||
|             //if this event has a valid state machine | ||||
|             //function pointer | ||||
|             if (ev.processEvent != NULL) | ||||
|             { | ||||
|                 //call the state machine method function  | ||||
|                 //and pass the event as parameter | ||||
|                 ev.processEvent(&ev); | ||||
|             } | ||||
|         //} | ||||
|     } | ||||
| } | ||||
							
								
								
									
										84
									
								
								03-software/ch/kb28/blinkerProject/xf/xf.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										84
									
								
								03-software/ch/kb28/blinkerProject/xf/xf.h
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,84 @@ | ||||
| /******************************************************************************/ | ||||
| /* FILENAME	: xf.h                                                            */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* GOAL		  : Offers the femto XF functions                                   */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* AUTHOR   : Medard Rieder / Pascal Sartoretti                               */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* DATE:    : original (Medard Rieder 08.2011)                                */ | ||||
| /*            corrections & simplified (Pascal Sartoretti 06.2016)            */ | ||||
| /******************************************************************************/ | ||||
| #ifndef XF_DEF | ||||
| #define XF_DEF | ||||
|  | ||||
| #include <stdint.h>         // usage of standard types | ||||
| #include <stdbool.h>        // usage of boolean types | ||||
| #include "../mcc_generated_files/mcc.h" | ||||
| #include "event.h" | ||||
|  | ||||
| #define  Time uint16_t      // time type | ||||
| #define  TimerID uint8_t    // identifier of timer (position in buffer) | ||||
|  | ||||
| typedef struct Timer_        // timer structure | ||||
| { | ||||
|     Time tm;                // time | ||||
|     Event ev;               // event to post | ||||
| } Timer; | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* depending on usage, change MAXTIMER and MAXEVENT                           */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| #define MAXTIMER 8          // number of timers in our system | ||||
| #define MAXEVENT 12         // number of events in our system  | ||||
|  | ||||
| #define NULLTIMER 0         // no value for time | ||||
| #define TICKINTERVAL 10     // this is the ticktimers duration | ||||
|  | ||||
|  | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| typedef struct XF           // the XF structure | ||||
| { | ||||
|     Timer timerList[MAXTIMER];         // the timers | ||||
|     Event eventQueue[MAXEVENT];        // the events | ||||
|     uint8_t in;                        // the events in pointer | ||||
|     uint8_t out;                       // the events out pointer | ||||
| } XF; | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Init the XF structure                                       */ | ||||
| /* INPUT        : -                                                           */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : Have to be called once                                      */ | ||||
| /******************************************************************************/ | ||||
| void XF_init(); | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Remove a timer in timers queue                              */ | ||||
| /* INPUT        : id - the timer id to remove                                 */ | ||||
| /*                inISR - (true if called in an ISR, else false)              */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : -                                                           */ | ||||
| /******************************************************************************/ | ||||
| void XF_unscheduleTimer(TimerID id, bool inISR); | ||||
| /******************************************************************************/ | ||||
| /* FUNCTION     : Decrement timers to post events if time elapsed             */ | ||||
| /* INPUT        : -                                                           */ | ||||
| /* OUTPUT       : -                                                           */ | ||||
| /* COMMENTS     : This function has to be called from the timer ISR           */ | ||||
| /******************************************************************************/ | ||||
| void XF_decrementAndQueueTimers(); | ||||
|  | ||||
| /********************************************************************************/ | ||||
| /* FUNCTION     : POST an Event                                                 */ | ||||
| /* INPUT        : target - the address of the object with the state machine     */ | ||||
| /*                processEvent - function pointer of the state machine function */ | ||||
| /*                id - the id of the event                                      */ | ||||
| /*                delay - the delay if the event is a timeout event             */ | ||||
| /*                data - user data                                              */ | ||||
| /* OUTPUT       : TimerId - the id of the timeout if the event is a timeout     */ | ||||
| /* COMMENTS     :                                                               */ | ||||
| /********************************************************************************/ | ||||
| TimerID POST(void* target, processEventT processEvent, uint8_t id, Time delay, int64_t data); | ||||
|  | ||||
| void XF_executeOnce(); | ||||
| #endif | ||||
|  | ||||
		Reference in New Issue
	
	Block a user