Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------------------------------------------------
- // Librairies
- //----------------------------------------------------------------------------
- #include "main.h" // all necessary librairies are included in main.h
- //----------------------------------------------------------------------------
- // Extern variables declaration
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Global variables declaration
- //----------------------------------------------------------------------------
- int ISR_Counter = 0;
- char counter_100ms;
- char isOk = 1; //OK: 1, Default: 0
- char checked = 0; //0: not checked yet, 1:already checked
- //----------------------------------------------------------------------------
- // Interrupts declaration
- //----------------------------------------------------------------------------
- #pragma interrupt_handler Timer_500us_ISR // handle 500us interrupts
- //----------------------------------------------------------------------------
- // Functions
- //----------------------------------------------------------------------------
- void Timer_500us_ISR(void)
- {
- M8C_EnableGInt; // Re-activate interrupts for ADC process
- Clear_Watchdog_Timer();
- ISR_Counter++;
- if(ISR_Counter >= 200) { //100ms
- ISR_Counter = 0;
- counter_100ms++;
- }
- if(counter_100ms == 5){ //every 500us
- if(checked == 0) {
- sendData(0x44,0x44,0x45); //send 01010101
- readData(0x44,0x44,0x45); //read and compare data
- checked = 1;
- }
- if(isOk == 0){
- PRT1DR^=0x01; //blink red led if default
- /*debug*/
- //PRT0DR^=0xFF;
- //PRT1DR^=0xFF;
- //PRT2DR^=0xFF;
- }
- counter_100ms = 0;
- }
- }
- void sendData(char data1, char data2, char data3){
- /*
- * Registers: PRT0DR, PRT1DR and PRT2DR
- */
- PRT0DR|=data1;
- PRT1DR|=data2; //write data on output register
- PRT2DR|=data3;
- }
- void readData(char data1, char data2, char data3){
- /*Read and compare to supplied data*/
- volatile char buff1, buff2, buff3;
- char checkSum1,checkSum2,checkSum3; //contain expected registers values
- /*checkSum1 = data1 | (data1<<1);
- checkSum2 = data2 | (data2<<1);
- checkSum3 = data3 | (data3<<1);*/
- checkSum1 = 0xEC;
- checkSum2 = 0x04;
- checkSum3 = 0xC;
- buff1 = PRT0DR;
- buff2 = PRT1DR;
- buff3 = PRT2DR;
- if(buff1 != checkSum1 || buff3 != checkSum3 || buff2 != checkSum2){
- isOk = 0;
- }else{
- PRT1DR|=0x02; //set active ok led bit
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement