123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
-
- #include "core.h"
- volatile unsigned int TMR0U=0;
- volatile DWORD Now;
- void eeWriteByte(unsigned char address, unsigned char value){
- EEDATA = value;
- EEADR = address;
-
- EECON1bits.EEPGD = 0;
- EECON1bits.CFGS = 0;
- EECON1bits.WREN = 1;
- INTCONbits.GIEH = 0;
- INTCONbits.GIEL = 0;
- EECON2 = 0x55;
- EECON2 = 0x0AA;
- EECON1bits.WR = 1;
- while(EECON1bits.WR){
- __asm nop __endasm;}
- if(EECON1bits.WRERR){
-
- }
- EECON1bits.WREN = 0;
- INTCONbits.GIEH = 1;
- INTCONbits.GIEL = 1;
- }
- unsigned char eeReadByte(unsigned char address){
- EEADR = address;
- EECON1bits.CFGS = 0;
- EECON1bits.EEPGD = 0;
- EECON1bits.RD = 1;
- return EEDATA;
- }
- #if CONFIG_SETUP==1
- extern void Setup();
- #endif
- #ifndef FRAISE_NONE
- extern void fraiseISR();
- #endif
- void coreInit(void)
- {
- #if CONFIG_SETUP==1
- Setup();
- #endif
-
- PORTZ = LATZ = 0;
- PORTZbits.RZ1 = LATZbits.LATZ1 = 1;
-
- T0CONbits.TMR0ON = 1;
- T0CONbits.T08BIT = 0;
- T0CONbits.T0CS = 0;
- T0CONbits.T0SE = 1;
- T0CONbits.PSA = 0;
- T0CONbits.T0PS2 = 0;
- T0CONbits.T0PS1 = 1;
- T0CONbits.T0PS0 = 1;
- INTCONbits.TMR0IE=1;
- INTCON2bits.TMR0IP=1;
-
- RCONbits.IPEN = 1;
- INTCONbits.GIEH = 1;
- INTCONbits.GIEL = 1;
-
-
- T2CONbits.T2CKPS0=1;
- PR2=255;
- T2CONbits.TMR2ON=1;
- }
- void main() {
- #ifdef UD_SETUP
- setup();
- #endif
- #ifdef UD_LOOP
- while(1) loop();
- #endif
- }
- void high_ISR(void)
- __shadowregs __interrupt 1
- {
- Now.word1= TMR0U;
- LOWER_LSB(Now)=TMR0L;
- LOWER_MSB(Now)=TMR0H;
-
- if(INTCONbits.TMR0IF) {
- TMR0U++;
- INTCONbits.TMR0IF=0;
- Now.word1= TMR0U;
- LOWER_LSB(Now)=TMR0L;
- LOWER_MSB(Now)=TMR0H;
- }
-
- #ifdef UD_HIGH
- highInterrupts();
- #endif
- }
- void low_ISR(void)
- __interrupt 2
- {
- fraiseISR();
-
- #ifdef UD_LOW
- lowInterrupts();
- #endif
- }
- unsigned unsigned long int time()
- {
- DWORD now;
- now.word1= TMR0U;
-
- LOWER_LSB(now)=TMR0L;
- LOWER_MSB(now)=TMR0H;
-
- if(now.word1 != TMR0U) {
- now.word1= TMR0U;
- LOWER_LSB(now)=TMR0L;
- LOWER_MSB(now)=TMR0H;
- }
-
- return now._dword;
- }
- __at(_PORTZ_ADDR) volatile unsigned char PORTZ;
- __at(_PORTZ_ADDR) volatile __PORTZbits_t PORTZbits;
- __at(_PORTZ_ADDR + _PORT_TO_LAT) volatile unsigned char LATZ;
- __at(_PORTZ_ADDR + _PORT_TO_LAT) volatile __LATZbits_t LATZbits;
- __at(_PORTZ_ADDR + _PORT_TO_TRIS) volatile unsigned char TRICZ;
- __at(_PORTZ_ADDR + _PORT_TO_TRIS) volatile __TRISZbits_t TRISZbits;
- __at(_PORTZ_ADDR + _PORT_TO_ANSEL) volatile unsigned char ANSELZ;
- __at(_PORTZ_ADDR + _PORT_TO_ANSEL) volatile __ANSELZbits_t ANSELZbits;
|