00001
00002
00003
00004
00005
00006 #include "piccolo_all.h"
00007 #define USE_OR_MASKS //"VAGY" művelettel egyesíthető makrók legyenek
00008 #define RD16_ON 0x80 //T1CON közvetlen írásához ez a "jó" makró
00009 #include "timers.h"
00010 #include "stdio.h"
00011
00032 #if !defined(USE_INTERRUPT)
00033 #error "Nincs definiálva az USE_INTERRUPT szimbólum!"
00034 #endif //USE_INTERRUPT
00035 #if !defined(USE_USB)
00036 #error "Nincs definiálva az USE_USB szimbólum!"
00037 #endif //USE_USB
00038
00039 char uc;
00040 volatile unsigned char hour,
00041 min,
00042 sec;
00043
00044
00045 #pragma interrupt hi_isr
00046 void hi_isr() {
00047 #if defined(USB_INTERRUPT)
00048 USBDeviceTasks();
00049 #endif //USB_INTERRUPT
00050 }
00051
00052
00053 #pragma interruptlow lo_isr
00054 void lo_isr() {
00055 if(PIR1bits.TMR1IF && PIE1bits.TMR1IE) {
00056 if((sec+=2)>59) {
00057 sec=0;
00058 if(++min>59) {
00059 min=0;
00060 if(++hour>23) hour=0;
00061 }
00062 }
00063 PIR1bits.TMR1IF=0;
00064 }
00065 }
00066
00067 void main(void) {
00068
00069
00070 RCONbits.IPEN=1;
00071 INTCONbits.GIEH=1;
00072 INTCONbits.GIEL=1;
00073 InitializeSystem();
00074
00075 T1CON = RD16_ON
00076 | T1_PS_1_1
00077 | T1_OSC1EN_ON
00078 | T1_SYNC_EXT_ON
00079 | T1_SOURCE_EXT;
00080 TMR1H=0;
00081 TMR1L=0;
00082 IPR1bits.TMR1IP=0;
00083 PIR1bits.TMR1IF=0;
00084 PIE1bits.TMR1IE=1;
00085 T1CONbits.TMR1ON = 1;
00086
00087 while (!usb_cdc_kbhit()) {
00088 ProcessIO();
00089 }
00090 #if defined(__18F4550)
00091 outString("PICCOLO-4550");
00092 #elif defined(__18F14K50)
00093 outString("PICCOLO-14K50");
00094 #endif
00095 outString(" - rtc.c program\n");
00096 while (1) {
00097 do {
00098 uc=usb_cdc_getc();
00099 } while (uc!='T' && uc!='S');
00100 switch (uc) {
00101 case 'S':
00102 outString("SET = 0x");
00103 T1CONbits.TMR1ON = 0;
00104 hour=get2hex();
00105 min=get2hex();
00106 sec=get2hex();
00107 TMR1H=0;
00108 TMR1L=0;
00109 T1CONbits.TMR1ON = 1;
00110 usb_cdc_putc(' ');
00111
00112 case 'T':
00113 printf("Time = %02u:%02u:%02u\r\n",hour,min,sec);
00114 break;
00115 }
00116 }
00117 }
00118
00119