📄 dongli_24h.lst
字号:
.................... return(sc1);
.................... return(0);
.................... }
....................
....................
.................... /* standard template: char *strrchr(const char *s, int c).
.................... Finds last occurrence of c in s */
....................
.................... char *strrchr(char *s, int c)
.................... {
.................... char *p;
....................
.................... for (p = 0; ; s++)
.................... {
.................... if (*s == c)
.................... p = s;
.................... if (*s == '\0')
.................... return(p);
.................... }
.................... }
.................... /* computes length of max initial segment of s1 consisting
.................... entirely of characters from s2 */
....................
.................... int *strspn(char *s1, char *s2)
.................... {
.................... char *sc1, *sc2;
....................
.................... for (sc1 = s1; *sc1 != 0; sc1++)
.................... for (sc2 = s2; ; sc2++)
.................... if (*sc2 == '\0')
.................... return(sc1 - s1);
.................... else if (*sc1 == *sc2)
.................... break;
.................... return(sc1 - s1);
.................... }
.................... /* standard template:
.................... char *strstr(const char *s1, const char *s2);
.................... Locates first occurence of character sequence s2 in s1;
.................... returns 0 if s2 is empty string
....................
.................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
.................... file to use the faster algorithm */
.................... char *strstr(char *s1, char *s2)
.................... {
.................... char *s, *t;
....................
.................... #ifdef FASTER_BUT_MORE_ROM
.................... if (*s2 == '\0')
.................... return(s1);
.................... #endif
....................
.................... while (*s1)
.................... {
.................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t);
....................
.................... if (*t == '\0')
.................... return s1;
.................... ++s1;
.................... #ifdef FASTER_BUT_MORE_ROM
.................... while(*s1 != '\0' && *s1 != *s2)
.................... ++s1;
.................... #endif
.................... }
.................... return 0;
.................... }
....................
.................... /* standard template: char *strtok(char *s1, const char *s2).
....................
.................... Finds next token in s1 delimited by a character from separator
.................... string s2 (which can be different from call to call). First call
.................... starts at beginning of s1 searching for first character NOT
.................... contained in s2; returns 0 if none is found.
.................... If one is found, it is the start of first token (return value).
.................... Function then searches from there for a character contained in s2.
.................... If none is found, current token extends to end of s1, and subsequent
.................... searches for a token will return 0. If one is found, it is
.................... overwritten by '\0', which terminates current token. Function saves
.................... pointer to following character from which next search will start.
.................... Each subsequent call, with 0 as first argument, starts searching
.................... from saved pointer */
....................
.................... char *strtok(char *s1, char *s2)
.................... {
.................... char *beg, *end;
.................... static char *save;
*
04D4: CLRF 29
....................
.................... beg = (s1)??s1: save;
.................... beg += strspn(beg, s2);
.................... if (*beg == '\0')
.................... {
.................... *save = ' ';
.................... return(0);
.................... }
.................... end = strpbrk(beg, s2);
.................... if (*end != '\0')
.................... {
.................... *end = '\0';
.................... end++;
.................... }
.................... save = end;
.................... return(beg);
.................... }
....................
.................... /*****************************************************************/
.................... /*Miscellaneous functions*/
.................... /* standard template
.................... maps error number in errnum to an error message string
.................... Returns: Pointer to string
.................... */
.................... #ifdef _ERRNO
.................... char * strerror(int errnum)
.................... {
.................... char s[15];
.................... switch( errnum)
.................... {
.................... case 0:
.................... strcpy(s,"no errors");
.................... return s;
.................... case EDOM :
.................... strcpy(s,"domain error");
.................... return s;
.................... case ERANGE:
.................... strcpy(s,"range error");
.................... return s;
.................... }
.................... }
.................... #ENDIF
.................... /* standard template: size_t strlen(const char *s).
.................... Computes length of s1 (preceding terminating 0) */
....................
.................... int *strlen(char *s)
.................... {
.................... char *sc;
....................
.................... for (sc = s; *sc != 0; sc++);
.................... return(sc - s);
.................... }
....................
.................... /* standard template: size_t stricmp(const char *s1, const char *s2).
.................... Compares s1 to s2 ignoring case (upper vs. lower) */
....................
.................... signed int stricmp(char *s1, char *s2)
.................... {
.................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
.................... s1++, s2++)
.................... if (*s1 == '\0')
.................... return(0);
.................... return((*s1 < *s2) ??-1: 1);
.................... }
....................
....................
.................... /* standard template: char *strlwr(char *s).
.................... Replaces uppercase letters by lowercase;
.................... returns pointer to new string s */
....................
.................... char *strlwr(char *s)
.................... {
.................... char *p;
....................
.................... for (p = s; *p != '\0'; p++)
.................... if (*p >= 'A' && *p <='Z')
.................... *p += 'a' - 'A';
.................... return(s);
.................... }
....................
....................
.................... /************************************************************/
....................
....................
.................... #endif
....................
.................... #ifndef getc
.................... #define getc getch
.................... #define getchar getch
.................... #define puts(s) {printf(s); putchar(13); putchar(10);}
.................... #define putc putchar
.................... #endif
.................... /* maps error number to an error message. Writes a sequence of characters to
.................... stderr stream thus: if s is not null then string pointed to by s follwed by
.................... a colon (:) and a space and the appropriate error message returned by strerror
.................... function with argument errno
....................
.................... Returns: no value
.................... */
....................
.................... #ifdef _ERRNO
.................... void perror(char *s)
.................... {
.................... if(s)
.................... fprintf(STDERR,"%s: ",s);
.................... fprintf(STDERR,"%s\r\n",strerror(errno));
.................... }
.................... #endif
.................... #endif
....................
.................... #include <dongli_24h.h>
.................... typedef unsigned int32 UDWORD;
.................... typedef unsigned long int UWORD;
.................... typedef unsigned char UCHAR;
.................... //报警时间存储
.................... #define a_year 0x10
.................... #define a_month 0x11
.................... #define a_date 0x12
.................... //终止时间存储
.................... #define e_year 0x14
.................... #define e_month 0x15
.................... #define e_date 0x16
....................
....................
.................... #define first_flag 0x18
.................... #define pd_time 0x19//存储切换时间间隔
....................
.................... //uchar up_flag=0 ;
.................... //**************************************
.................... struct time
.................... {
.................... uchar year;
.................... uchar month;
.................... uchar day;
.................... uchar hour;
.................... uchar min;
.................... }realtime,endtime,startime,altime;
....................
.................... //**************************************************************
.................... void write7279(unsigned char cmd,unsigned char dta);
.................... void get_endate(uchar year,uchar month,uchar date);
.................... //void disp_time();//显示时间
.................... unsigned char HEX_TO_BCD(unsigned char x);
.................... char delay_int(UWORD c_time);
....................
.................... //*****************************************************************
.................... //#use delay(clock=4000000,RESTART_WDT)
.................... //#fuses XT,WDT
....................
....................
.................... #include <rs232.c>
.................... #include <rs232.h>
.................... #define frame_start 0
.................... #define frame_year 1
.................... #define frame_month 2
.................... #define frame_day 3
.................... #define frame_chk 4
.................... #define frame_end 5
....................
.................... //UART RECEIVE BUF
.................... char rx_buffer[8]; //接收缓冲区
.................... char rx_counter=0;
04D5: CLRF 46
.................... //UART TRANSMIT BUF
.................... char tx_buffer[8]; //发送缓冲区
.................... char tx_counter=0;
04D6: CLRF 4F
....................
....................
.................... #byte TXSTA=0X98
.................... #byte RCSTA=0X18
.................... #byte SPBRG=0X99
.................... #byte TXREG=0X19
.................... #byte RCREG=0X1A
.................... //*********************************************************************
.................... void disdata();
.................... void EEPROM_write_parameter(UCHAR addr,uchar data) ;
.................... uchar EEPROM_read_parameter(UCHAR addr) ;
....................
.................... #use delay(clock=4000000,RESTART_WDT)
*
0045: MOVLW 6C
0046: MOVWF 04
0047: MOVF 00,W
0048: BTFSC 03.2
0049: GOTO 05B
004A: MOVLW 01
004B: MOVWF 78
004C: MOVLW BF
004D: MOVWF 77
004E: CLRWDT
004F: DECFSZ 77,F
0050: GOTO 04E
0051: DECFSZ 78,F
0052: GOTO 04C
0053: MOVLW 4A
0054: MOVWF 77
0055: DECFSZ 77,F
0056: GOTO 055
0057: NOP
0058: CLRWDT
0059: DECFSZ 00,F
005A: GOTO 04A
005B: RETLW 00
.................... #fuses XT,WDT
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=,bits=8)
....................
.................... void ini_rs232()
.................... {
.................... TXSTA=0x00;
*
0331: BSF 03.5
0332: CLRF 18
.................... RCSTA=0X90;
0333: MOVLW 90
0334: BCF 03.5
0335: MOVWF 18
.................... SPBRG=0x06;
0336: MOVLW 06
0337: BSF 03.5
0338: MOVWF 19
....................
.................... }
0339: BCF 03.5
033A: BCF 0A.3
033B: BCF 0A.4
033C: GOTO 50F (RETURN)
....................
.................... uchar getchk(char x,char y,char z )
.................... {
.................... uchar t;
.................... t=x;
*
01E3: MOVF 6B,W
01E4: MOVWF 6E
.................... t=t^y;
01E5: MOVF 6C,W
01E6: XORWF 6E,F
.................... t=t^z;
01E7: MOVF 6D,W
01E8: XORWF 6E,F
.................... return t;
01E9: MOVF 6E,W
01EA: MOVWF 78
.................... }
....................
....................
.................... void send_cmd(uchar fun)
.................... {
.................... UCHAR i;
.................... tx_buffer[0]=0xF5;
.................... tx_buffer[frame_year]=0x06;//realtime.time.year;
.................... tx_buffer[frame_month]=0x11;//realtime.time.month;
.................... tx_buffer[frame_day]=0x30;//realtime.time.date;
.................... tx_buffer[frame_chk]=getchk(0x06,0x11,0x30);
.................... tx_buffer[6]=0x34;
.................... for(i=0;i<8;i++)
.................... {
.................... // putc(tx_buffer[i]);
.................... TXREG=tx_buffer[i];
.................... delay_ms(10);
.................... }
.................... }
....................
....................
....................
....................
.................... /**************************************************************
.................... * 函数原型:void serial_rx_isr(void)
.................... * 功 能: 接收中断接收一串口数据,写入接收缓冲区
.................... * 说 明:
....................
.................... ****************************************************************/
....................
.................... #int_rda //接收中断处理
....................
.................... void serial_rx_isr(void)
....................
.................... {
.................... uchar rx_byte;
.................... //rx_byte=getc();
.................... restart_wdt();
*
01C8: CLRWDT
.................... rx_byte=RCREG;
01C9: MOVF 1A,W
01CA: MOVWF 69
.................... if(rx_byte==0xF5)//一个帧头就行了,因为有效数据值不可能是F5,也部可能是0X34
.................... rx_counter=0;
01CB: MOVF 69,W
01CC: SUBLW F5
01CD: BTFSC 03.2
01CE: CLRF 46
.................... rx_buffer[rx_counter++]=rx_byte;
01CF: MOVF 46,W
01D0: INCF 46,F
01D1: ADDLW 3E
01D2: MOVWF 04
01D3: MOVF 69,W
01D4: MOVWF 00
.................... if(rx_byte==0x34)
.................... {
01D5: MOVF 69,W
01D6: SUBLW 34
01D7: BTFSS 03.2
01D8: GOTO 22B
.................... disable_interrupts(int_rda);//开着中断,tx_counter的值就不停在变
01D9: BSF 03.5
01DA: BCF 0C.5
.................... disable_interrupts(int_TIMER1);//成功解密后重新显示时间
01DB: BCF 0C.0
.................... disdata();
.................... }
.................... }
....................
*
022B: BCF 0C.5
022C: BCF 0A.3
022D: BCF 0A.4
022E: GOTO 029
.................... void disdata()
.................... {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -