/*********************************************************************** 2011 (C) Alex Dobrianski stepper modtors controller module This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see Design and development by Team "Plan B" is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. http://creativecommons.org/licenses/by-sa/3.0/ ************************************************************************/ /*********************************************************************** see www.adobri.com for communication protocol spec ************************************************************************/ // needs to spec processor - C and ASM code is different // [1 GYRO]->[2 MEM]-> [3 POW] -> [4 CM] -> [5 BT] -| // A | // -------------------------------------------------- #define MY_UNIT '5' #define MAX_COM_TOPOLOGY_UNIT '5' //#define ALLOW_RELAY_TO_NEW // needs to spec processor - C and ASM code is different #ifdef __18CXX #ifdef __16F88 #define _16F88 1 #endif #ifdef __16F884 #define _16F884 1 #endif #ifdef __16F724 // the same as 16F884 #define _16F884 1 #endif #ifdef __18F2321 #define _18F2321 1 #endif #endif // it can be only master support: pic works in master mode only=> uncomment this line if // no multimaster support on a bus #define I2C_ONLY_MASTER 1 // master support done via interrupts and firmware - commenting next line and I2C will be a software work #define I2C_INT_SUPPORT 1 // define speed send data over com - sequence should be: // ptrSpeed = &AllGyro.TempL; pointer to the last transfwered byte -1 // LenSpeed = 17; bytes to transfer // SpeedSendLocked = 0; prepear lock mode for speed send // SpeedSendUnit = 0; unit at the end was not send et // SpeedSendWithESC = 1; does (or does not if == 0) send data using esc on units addreses // SpeedESCwas = 0; no esc on first byte et // SpeedSend = 1; LAST TO INITIATE // TXIE = 1; and run over interrupts #define SPEED_SEND_DATA 1 // if such fucntionality does not requare then commneting this line saved code in ISR /* #ifdef _PIC16F88 #include "int16CXX.H" #define RAM_BANK_0 0 #define RAM_BANK_1 1 #define RAM_BANK_2 2 #define RAM_BANK_3 3 #define TIMER0_CONTROL_REG OPTION_REG #define TIMER0_BYTE TMR0 #define TIMER0_INT_ENBL TMR0IE #define TIMER0_INT_FLG TMR0IF #define FSR_REGISTER FSR #define PTR_FSR INDF #define INT0_EDG INTEDG #define INT0_FLG INT0IF #define INT0_ENBL INT0IE #define I2CPORT PORTB #define I2CTRIS TRISB #define I2C_SDA 1 #define I2C_SCL 4 #define TIMER0_INT_ENBL TMR0IE #define TIMER0_INT_FLG TMR0IF #endif */ #include "commc0.h" // // additional code: unsigned char CameraSTART; unsigned char JpegLenH2; unsigned char JpegLenH1; unsigned char JpegLenH; unsigned char JpegLenL; bit CMDGetLength; bit CMDReset; bit CameraOK; bit CMDpicture; bit CMDget; bit CMDpicFrmt; #include "commc1.h" // // additional code: unsigned char CallBkComm(void); // return 1 == process queue; 0 == do not process; // 2 = do not process and finish process 3 == process and finish internal process // in case 0 fucntion needs to pop queue byte by itself unsigned char CallBkI2C(void); // return 1 == process queue; 0 == do not process; // 2 = do not process and finish process 3 == process and finish internal process // in case 0 fucntion needs to pop queue byte by itself unsigned char CallBkMain(void); // 0 = do continue; 1 = process queues void Reset_device(void); void ShowMessage(void); void ProcessCMD(unsigned char bByte); unsigned char getchI2C(void); void putch(unsigned char simbol); void putchWithESC(unsigned char simbol); unsigned char getch(void); void main() { unsigned char bWork; /*if (POR_) // this is can be sync of a timer from MCLR { if (SetSyncTime) { TMR1L = 0; // must be delay in 2MHz clock TMR1H = 0; TMR130 = setTMR130; TMR1SEC = setTMR1SEC; TMR1MIN = setTMR1MIN; TMR1HOUR = setTMR1HOUR; TMR1DAY = setTMR1DAY; } }*/ Reset_device(); // needs to check what is it: //if (TO) // Power up or MCLR { // Unit == 1 (one) is ADC and unit == 2 (two) is DAC // Unit == 3 Gyro //UnitADR = '1'; UnitADR = '4'; // stepper motor module unit 4 //UnitADR = '4'; #include "commc6.h" CMDReset = 0; CameraSTART = 0; CMDGetLength = 0; CMDReset = 0; CameraOK = 0; CMDpicture = 0; CMDget = 0; CMDpicFrmt = 0; } PEIE = 1; // bit 6 PEIE: Peripheral Interrupt Enable bit // 1 = Enables all unmasked peripheral interrupts // 0 = Disables all peripheral interrupts GIE = 1; // bit 7 GIE: Global Interrupt Enable bit // 1 = Enables all unmasked interrupts // 0 = Disables all interrupts RBIF = 0; ShowMessage(); bitset(PORTA,3); //bitset(SSPCON,4); // set clock high; #include "commc7.h" /////////////////////////////////////////////////////////////////////// } // at the end will be Sleep which then continue to main #define SPBRG_9600 51 #define SPBRG_19200 25 #define SPBRG_38400 12 #define SPBRG_57600 8 #define SPBRG_SPEED SPBRG_9600 #include "commc2.h" // additional code: void ProcessCMD(unsigned char bByte) { if (!Main.getCMD) { // additional code from comm without CMD processing #include "commc3.h" // additional code: if (CameraSTART > 8) { if (CMDReset) { if (CameraSTART > 61) { CMDReset = 0; RESET_CMD_0: CameraSTART = 0; //ProcInside = 0; Main.getCMD = 0; goto SKIP_BYTE; } } goto INC_COUNT; } else if (CameraSTART == 8) { if (CMDGetLength) { JpegLenL = bByte; //CameraSTART = 0; CMDGetLength = 0; goto RESET_CMD_0;//:CameraSTART = 0; ProcInside = 0;Main.getCMD = 0; } goto INC_COUNT; } else if (CameraSTART == 7) { if (CMDGetLength) JpegLenH = bByte; goto INC_COUNT; } else if (CameraSTART == 6) { if (CMDGetLength) JpegLenH1 = bByte; INC_COUNT: CameraSTART++; goto SKIP_BYTE; } else if (CameraSTART == 5) { if (CMDGetLength) JpegLenH2 = bByte; goto INC_COUNT; } else if (CameraSTART == 4) { if (CMDpicture) { CameraSTART = 0; // now needs to read length of a jpeg picture //send to camera 56 00 34 01 00 -> 76 00 43 00 02 00 00 (7 bytes) putmsg("\x56\x00\x34\x01\x00",5); CMDpicture = 0; CMDGetLength = 1; goto SKIP_BYTE; } else if (CMDGetLength) { } else if (CMDpicFrmt) { CameraSTART = 0; CMDpicFrmt = 0; // Now needs todo reset goto RESET_CMD; } else if (CMDget) { CameraSTART = 9; goto SKIP_BYTE; } goto INC_COUNT; } else if (CameraSTART == 3) { // can be enything after this if (bByte == 00) CameraSTART++; if (CMDReset) { CameraSTART = 9; //CMDReset = 0; //goto SKIP_BYTE; } goto SKIP_BYTE; } else if (CameraSTART == 2) { if (bByte == 0x26) // response from Reset { CameraOK = 1; } else if (bByte == 0x36) // picture taken { // TBD needs to store time of taken picture // and Gyro positions } else if (bByte == 0x34) // reading length of the file { } else if (bByte == 0x31) // image size OK { } else if (bByte == 0x32) // geting jpeg { } goto INC_COUNT; } else if (CameraSTART == 1) { // must be 00 if (bByte) CameraSTART = 0; else CameraSTART = 2; goto SKIP_BYTE; } #include "commc4.h" // additional code: else if (bByte == 'R') // reset camera { RESET_CMD: // send to camera 56 00 26 00 -> putmsg("\x56\x00\x26\x00",4); CMDReset = 1; CameraOK = 0; // responce 76 00 26 00 00 ...(total 71 bytes).. 6e 69 74 20 65 6e 64 0d 0a ("nit end 0xod 0xoa") // dalay must be around 40ms } else if (bByte == 'P') // take picture { //send to camera 56 00 36 01 00 -> responce 76 00 36 00 00 putmsg("\x56\x00\x36\x01\x00",5); CMDpicture = 1; } else if (bByte == 'G') // get jpeg picture { //send to camera 56 00 32 0C 00 0A 00 00 MH ML 00 00 KH KL XX XX putmsg("\x56\x00\x32\x0c\x00\x0a\x00\x00",8); putmsg("\x00\x00\x00\x00",4); putch(JpegLenH); putch(JpegLenL); putmsg("\x00\x0a",2); CMDget = 1; //CameraSTART = 9; // responce -> 76 00 32 00 00 FF d8 . . . . FD D9 } else if (bByte == 'B') // big picture 640 480 { putmsg("\x56\x00\x31\x05\x04\x01\x00\x19\x00",9); CMDpicFrmt = 1; // responce must be 76 00 31 00 00 } else if (bByte == 'M') // medium picture 320 240 { putmsg("\x56\x00\x31\x05\x04\x01\x00\x19\x11",9); CMDpicFrmt = 1; // responce must be 76 00 31 00 00 } else if (bByte == 'S') // medium picture 160 120 { putmsg("\x56\x00\x31\x05\x04\x01\x00\x19\x22",9); CMDpicFrmt = 1; // responce must be 76 00 31 00 00 } else if (bByte == 0x76) // this will be responce from camera { goto INC_COUNT; //CameraSTART = 1; } SKIP_BYTE: } // do not confuse: this is a else from Main.getCMD == 1 } unsigned char CallBkComm(void) // return 1 == process queue; 0 == do not process; // 2 = do not process and finish process 3 == process and finish internal process { // in case 0 fucntion needs to pop queue byte by itself unsigned char bBy; if (CMDget) // if this is internal procesing jpeg ? { if (CameraSTART < 5) { if (CameraSTART == 1) { bBy = JpegLenH2; goto MOD_QUEUE; } else if (CameraSTART == 2) { bBy = JpegLenH1; goto MOD_QUEUE; } else if (CameraSTART == 3) { bBy = JpegLenH; goto MOD_QUEUE; } else if (CameraSTART == 4) { bBy = JpegLenL; MOD_QUEUE: AInQu.Queue[AInQu.iExit] = bBy; } CameraSTART++; goto CHECK_ESC_B; } else //if (CameraSTART >= 5) // and this is a jpeg body { if (JpegLenL) JpegLenL--; else { JpegLenL--; if (JpegLenH) JpegLenH--; else { // jpeg done CMDget = 0; CameraSTART = 0; return 2; } } CHECK_ESC_B: bBy = AInQu.Queue[AInQu.iExit]; // function called when Queue is not empty; check next pop byte in queue if (bBy == UnitADR) // needs to ESC goto SET_FOR_ESC_ADR; else if (bBy == '@') // needs to ESC { SET_FOR_ESC: //if (UseCom) { SET_FOR_ESC_ADR: Main.ESCNextByte = 1; } //else // I2C.ESCI2CChar = 1; } else if (bBy == '>') // needs to ESC goto SET_FOR_ESC; else { Main.ESCNextByte = 0; I2C.ESCI2CChar = 0; } // TBD needs to check FF D9 - this will be error if length not matched } } return 1; // this will process next byte } unsigned char CallBkI2C(void) // return 1 == process queue; 0 == do not process; // 2 = do not process and finish process 3 == process and finish internal process { // in case 0 fucntion needs to pop queue byte by itself return 1; } unsigned char CallBkMain(void) // 0 = do continue; 1 = process queues { //if (Timer0Waiting) //{ // if (Timer0Fired) // Timer0Waiting = 0; // else // return 0; //} return 1; } #pragma codepage 1 void Reset_device(void) { #ifdef __PIC24H__ // Configure Oscillator to operate the device at 40Mhz // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 8M*40/(2*2)=80Mhz for 8M input clock PLLFBD=42; // 42// M=40 // for value = 50 it can be 92.125MHz and 46MIPS needs to make shure that FIN will be more then 4MHz and less 8MHz // OCTUN set more then 8MHz can be wrong CLKDIVbits.PLLPOST=0; // N2=2 PLL VCO Output Divider Select bits (also denoted as æN2Æ, PLL postscaler) // 00 = Output/2 CLKDIVbits.PLLPRE=0; // N1=2 PLL Phase Detector Input Divider bits (also denoted as æN1Æ, PLL prescaler) // 00000 = Input/2 (default) OSCTUN=0;//0x14; // Tune FRC oscillator, if FRC is used // bit 5-0 TUN<5:0>: FRC Oscillator Tuning bits(1) // 111111 = Center frequency -0.375% (7.345 MHz) // 100001 = Center frequency -11.625% (6.52 MHz) // 100000 = Center frequency -12% (6.49 MHz) // 011111 = Center frequency +11.625% (8.23 MHz) // 011110 = Center frequency +11.25% (8.20 MHz) // 000001 = Center frequency +0.375% (7.40 MHz) // 000000 = Center frequency (7.37 MHz nominal) // 010100 = 8MHz RCONbits.SWDTEN=0; // Disable Watch Dog Timer ??? // Clock switch to incorporate PLL __builtin_write_OSCCONH(0x01); // Initiate Clock Switch to Primary // Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONL(0x01); // Start clock switching // bit 7 CLKLOCK: Clock Lock Enable bit 0 = Clock switching is enabled, system clock source can be modified by clock switching // bit 6 IOLOCK: Peripheral Pin Select Lock bit 0 = Peripherial pin select is not locked, write to peripheral pin select registers allowed // bit 5 LOCK: PLL Lock Status bit (read-only) // bit 4 Unimplemented: Read as æ0Æ // bit 3 CF: Clock Fail Detect bit (read/clear by application) // bit 2 Unimplemented: Read as æ0Æ // bit 1 LPOSCEN: Secondary (LP) Oscillator Enable bit 0 = Disable secondary oscillator // bit 0 OSWEN: Oscillator Switch Enable bit 1 = Request oscillator switch to selection specified by NOSC<2:0> bits while (OSCCONbits.COSC != 0b001); // Wait for Clock switch to occur check for: // 011 = Primary oscillator (XT, HS, EC) with PLL while(OSCCONbits.LOCK!=1) {}; // Wait for PLL to lock // bit 5 LOCK: PLL Lock Status bit (read-only) // 1 = Indicates that PLL is in lock, or PLL start-up timer is satisfied // 0 = Indicates that PLL is out of lock, start-up timer is in progress or PLL is disabled // disable analog AD1CON1bits.ADON = 0; // and switch analog pins to digital AD1PCFGL = 0xffff; //AD1PCFGH = 0xffff; // porta is not re-mappable and on 502 device it is RA0-RA4 // SPI output in FLASH mem terminoligy: // SSCLOCK RA0(pin2), SSDATA_IN RA1(pin3), SSDATA_OUT RA2(pin9), SSCS RA3(pin10) // 0 0 IN 1 TRISA = 0b00000100; //0 = Output, 1 = Input PORTA = 0b00001000; // this kaind funny, and for PIC24 and up = PRX pins can be reassigned to differrent preferias // additionaly needs to remember on which pin sits which PRX : // VSIAK SVERCHOK ZNAI SVOI SHESTOK __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock port remapping // INT0 == pin 16 // INT1 == pin 21 == PR10 #ifdef HI_TECH_C #else IN_FN_PPS_INT1 = IN_PIN_PPS_RP10; // RPINR0 // INT2 == pin 22 == PR11 IN_FN_PPS_INT2 = IN_PIN_PPS_RP11; // PR5 - Serial RX Pin 14 IN_FN_PPS_U1RX = IN_PIN_PPS_RP5; // RR6 - Serial TX Pin 15 OUT_PIN_PPS_RP6 = OUT_FN_PPS_U1TX; #endif // I2C: // SCL1 = I2C clock Pin 17 (this is NOT alernative I2c set as FPOR = 1 in configuration) // SDA1 = I2C data Pin 18 this two pins permamet __builtin_write_OSCCONL(OSCCON | 0x40); //lock back port remapping //RBPU_ = 0; //bitclr(OPTION,RBPU_); //Each of the PORTB pins has a weak internal pull-up. A //single control bit can turn on all the pull-ups. This is //performed by clearing bit RBPU (OPTION_REG<7>). //The weak pull-up is automatically turned off when the //port pin is configured as an output. The pull-ups are //disabled on a Power-on Reset. INT0_ENBL = 0; // disable external interrupt for GYRO 1 INT1IE = 0; // disable external interrupt for GYRO2 enable_uart(); //Setup the hardware UART for 20MHz at 9600bps // next two bits has to be set after all intialization done //PEIE = 1; // bit 6 PEIE: Peripheral Interrupt Enable bit // 1 = Enables all unmasked peripheral interrupts // 0 = Disables all peripheral interrupts //GIE = 1; // bit 7 GIE: Global Interrupt Enable bit // 1 = Enables all unmasked interrupts // 0 = Disables all interrupts enable_I2C(); TIMER0_INT_FLG = 0; // clean timer0 interrupt TIMER0_INT_ENBL = 0; // diasable timer0 interrupt TMR1IF = 0; // clean timer0 interrupt TMR1IE = 0; // diasable timer0 interrupt INT0_EDG = 1; // 1 = Interrupt on negative edge INT0_FLG = 0; // clean extrnal interrupt RB0 pin 6 INT1IF = 0; INTEDG1 = 1; INT2IF = 0; INTEDG2 = 1; #else // this is will be better at the begining of a program OSCCON = 0b01110000; //OSCILLATOR CONTROL REGISTER (ADDRESS 8Fh) // bit 6-4 IRCF<2:0>: Internal RC Oscillator Frequency Select bits // 000 = 31.25 kHz // 001 = 125 kHz // 010 = 250 kHz // 011 = 500 kHz // 100 = 1 MHz // 101 = 2 MHz // 110 = 4 MHz // 111 = 8 MHz // bit 3 OSTS: Oscillator Start-up Time-out Status bit(1) // 1 = Device is running from the primary system clock // 0 = Device is running from T1OSC or INTRC as a secondary system clock // Note 1: Bit resets to æ0Æ with Two-Speed Start-up mode and LP, XT or HS selected as the // oscillator mode. // bit 2 IOFS: INTOSC Frequency Stable bit // 1 = Frequency is stable // 0 = Frequency is not stable // bit 1-0 SCS<1:0>: Oscillator Mode Select bits // 00 = Oscillator mode defined by FOSC<2:0> // 01 = T1OSC is used for system clock // 10 = Internal RC is used for system clock // 11 = Reserved #ifdef _NOT_SIMULATOR while((OSCCON&0b00000100) == 0); //Wait for frequency to stabilize #endif #ifdef _18F2321 PLLEN = 1; #ifdef _NOT_SIMULATOR while((OSCCON&0b00000100) == 0); //Wait for frequency to stabilize #endif ADCON0 = 0b00000000; ADCON1 = 0b00001111; // SPI output in FLASH mem terminoligy: // SSCLOCK RA7(pin9), SSDATA_IN RA6(pin10), SSDATA_OUT RA4(pin6), SSCS RA3(pin5) // 0 0 IN 1 TRISA = 0b00010000; //0 = Output, 1 = Input PORTA = 0b00001000; // RB0 - external INT Pin 21 // RB1 - external INT Pin 22 TRISB = 0b00000011; //0 = Output, 1 = Input PORTB = 0b00000000; // RC7 - Serial RX Pin 18 // RC6 - Serial TX Pin 17 // I2C: // RC3 - SCL = I2C clock Pin 14 // RC4 - SDA = I2C data Pin 15 TRISC = 0b10011000; //0 = Output, 1 = Input PORTC = 0b01000000; //RBPU_ = 0; //bitclr(OPTION,RBPU_); //Each of the PORTB pins has a weak internal pull-up. A //single control bit can turn on all the pull-ups. This is //performed by clearing bit RBPU (OPTION_REG<7>). //The weak pull-up is automatically turned off when the //port pin is configured as an output. The pull-ups are //disabled on a Power-on Reset. // RE3 (pin1) MCLR == input //TRISE = 0x00001000; PORTE = 0b11111111; INT0_ENBL = 0; // disable external interrupt for GYRO 1 INT1IE = 0; // disbalke external interrupt for GYRO2 #else // done _18F2321 #ifdef _16F884 ANSEL = 0b00000000; //Turn pins to Digital instead of Analog CM2CON0 = 0b00000111; //Turn off comparator on RA port CM1CON0 = 0b00000111; // for each unit it is individual // RA0,1,2,3,4 this will be stepper motor control 1A,2A,1B,2B,ENBL //TRISA = 0b10100000; //0 = Output, 1 = Input //PORTA = 0b00000000; // serial FLASH pin assignment // SSCLOCK RA7(pin16), SSDATA_IN RA6(pin15), SSDATA_OUT RA4, SSCS RA3 // 0 0 IN 1 TRISA = 0b00110000; //0 = Output, 1 = Input PORTA = 0b00001000; // SSCS set high // RB0 - external INT Pin 6 TRISB = 0b00000001; //0 = Output, 1 = Input PORTB = 0b11111110; // RC6 - Serial Out Pin 25 // RC7 - Serial In Pin 26 // I2C: // RC3 - SCL = I2C clock Pin 18 // RC4 - SDA = I2C data Pin 23 // RB0 - external INT Pin 33 TRISC = 0b10011000; //0 = Output, 1 = Input PORTC = 0b01000000; //RBPU_ = 0; //bitclr(OPTION,RBPU_); //Each of the PORTB pins has a weak internal pull-up. A //single control bit can turn on all the pull-ups. This is //performed by clearing bit RBPU (OPTION_REG<7>). //The weak pull-up is automatically turned off when the //port pin is configured as an output. The pull-ups are //disabled on a Power-on Reset. TRISD = 0b11111111; //0 = Output, 1 = Input PORTD = 0b00000000; // RE7 (pin1) MCLR == input TRISE = 0b11111111; //0 = Output, 1 = Input TRISE = 0b10000000; INT0_ENBL = 0; // disable external interrupt for GYRO 1 #else // done _18F2321 & _16F884 ANSEL = 0b00000000; //Turn pins to Digital instead of Analog CMCON = 0b00000111; //Turn off comparator on RA port // for each unit it is individual // RA0,1,2,3,4 this will be stepper motor control 1A,2A,1B,2B,ENBL //TRISA = 0b10100000; //0 = Output, 1 = Input //PORTA = 0b00000000; // RA5 MCLR == input // serial FLASH pin assignment // SSCLOCK RA7(pin16), SSDATA_IN RA6(pin15), SSDATA_OUT RA4(pin3), SSCS RA3(pin2) // 0 0 IN 1 TRISA = 0b00110000; //0 = Output, 1 = Input PORTA = 0b00001000; // SSCS set high // RB5 - Serial Out Pin 11 // RB2 - Serial In Pin 8 // I2C: // RB4 - SCL = I2C clock Pin 10 // RB1 - SDA = I2C data Pin 7 // RB0 - external INT Pin 6 // RB2 - serial input // RB5 - serial out TRISB = 0b00010111; //0 = Output, 1 = Input PORTB = 0b11111111; //RBPU_ = 0; //bitclr(OPTION,RBPU_); //Each of the PORTB pins has a weak internal pull-up. A //single control bit can turn on all the pull-ups. This is //performed by clearing bit RBPU (OPTION_REG<7>). //The weak pull-up is automatically turned off when the //port pin is configured as an output. The pull-ups are //disabled on a Power-on Reset. INT0_ENBL = 0; // disable external interrupt for GYRO 1 #endif #endif //RBIF = 0; //RBIE = 1; enable_uart(); //Setup the hardware UART for 20MHz at 9600bps // next two bits has to be set after all intialization done //PEIE = 1; // bit 6 PEIE: Peripheral Interrupt Enable bit // 1 = Enables all unmasked peripheral interrupts // 0 = Disables all peripheral interrupts //GIE = 1; // bit 7 GIE: Global Interrupt Enable bit // 1 = Enables all unmasked interrupts // 0 = Disables all interrupts enable_I2C(); TIMER0_INT_FLG = 0; // clean timer0 interrupt TIMER0_INT_ENBL = 0; // diasable timer0 interrupt TMR1IF = 0; // clean timer0 interrupt TMR1IE = 0; // diasable timer0 interrupt INT0_EDG = 0; // high -> low == interrupt INT0_FLG = 0; // clean extrnal interrupt RB0 pin 6 #ifdef _18F2321 INT1IF = 0; INTEDG1 = 0; #endif //INT0IE = 1; // enable external interrupt #endif } /* void Reset_device(void) { // this is will be better at the begining of a program OSCCON = 0b01110000; //OSCILLATOR CONTROL REGISTER (ADDRESS 8Fh) // bit 6-4 IRCF<2:0>: Internal RC Oscillator Frequency Select bits // 000 = 31.25 kHz // 001 = 125 kHz // 010 = 250 kHz // 011 = 500 kHz // 100 = 1 MHz // 101 = 2 MHz // 110 = 4 MHz // 111 = 8 MHz // bit 3 OSTS: Oscillator Start-up Time-out Status bit(1) // 1 = Device is running from the primary system clock // 0 = Device is running from T1OSC or INTRC as a secondary system clock // Note 1: Bit resets to ‘0’ with Two-Speed Start-up mode and LP, XT or HS selected as the // oscillator mode. // bit 2 IOFS: INTOSC Frequency Stable bit // 1 = Frequency is stable // 0 = Frequency is not stable // bit 1-0 SCS<1:0>: Oscillator Mode Select bits // 00 = Oscillator mode defined by FOSC<2:0> // 01 = T1OSC is used for system clock // 10 = Internal RC is used for system clock // 11 = Reserved #ifdef _NOT_SIMULATOR while((OSCCON&0b00000100) == 0); //Wait for frequency to stabilize #endif ANSEL = 0b00000000; //Turn pins to Digital instead of Analog CMCON = 0b00000111; //Turn off comparator on RA port // for each unit it is individual // RA0,1,2,3,4,7 this will be DATA0,1,2,3,4,5 TRISA = 0b11110000; //0 = Output, 1 = Input PORTA = 0b00000000; // RB5 - Serial Out Pin 11 // RB2 - Serial In Pin 8 // I2C: // RB4 - SCL = I2C clock Pin 10 // RB1 - SDA = I2C data Pin 7 // RB2 - serial input // RB5 - serial out TRISB = 0b00010110; //0 = Output, 1 = Input //RBPU_ = 0; //bitclr(OPTION,RBPU_); //Each of the PORTB pins has a weak internal pull-up. A //single control bit can turn on all the pull-ups. This is //performed by clearing bit RBPU (OPTION_REG<7>). //The weak pull-up is automatically turned off when the //port pin is configured as an output. The pull-ups are //disabled on a Power-on Reset. PORTB = 0b11111111; //RBIF = 0; //RBIE = 1; enable_uart(); //Setup the hardware UART for 20MHz at 9600bps // next two bits has to be set after all intialization done //PEIE = 1; // bit 6 PEIE: Peripheral Interrupt Enable bit // 1 = Enables all unmasked peripheral interrupts // 0 = Disables all peripheral interrupts //GIE = 1; // bit 7 GIE: Global Interrupt Enable bit // 1 = Enables all unmasked interrupts // 0 = Disables all interrupts enable_I2C(); } */ void ShowMessage(void) { // if message initiated by unit needs to check then it is possible to do: while(!Main.prepStream) // this will wait untill no relay message { } // in a case of a CMD replay it is safly to skip that check - unit allow to send message in CMD mode putch(UnitADR); // this message will circle over com and will be supressed by unit Puts("~"); putch(UnitADR); } #include "commc8.h"