----- Original Message ----- = From: "James Newton, Host" To: "'Microcontroller discussion list - Public.'" Sent: Thursday, May 25, 2006 6:17 AM Subject: RE: [PIC]: Code_mystery BRX.asm Hello! I=B4m very sorry for my email to the Piclist.! I=B4m diden=B4t mean that Mr Olin and several others people have to lie wakeful on the night because of me! Next time I will ask a question who only can replays with YES or NO. Regards =C5keN Age: 65 By now, I would have expected Olin to tell you that the reason this is not working is that there are lines of code without comments. Every line of code must be commented before he will believe that you know what that line of code is supposed to accomplish. There is some wisdom in that. Or, Olin (or others) will tell you that the code you have posted here is too long. That you must reduce the code to the minimum to reproduce the error. I will tell you that I have no clue why it doesn't work, but I would start by changing the main code so that ALL it does is call the EEPROM write routine to write 10 consecutive values (0,1,2,3,4,5,6,7,8,9,A) and see if it put the 9 and A over the 0 and 1. If so, the bug is in the EEPROM write routine, if not, the bug is in the code that calls the EEPROM write routine. --- James Newton: PICList webmaster/Admin mailto:jamesnewton@piclist.com 1-619-652-0593 phone http://www.piclist.com/member/JMN-EFP-786 PIC/PICList FAQ: http://www.piclist.com > -----Original Message----- > From: piclist-bounces@mit.edu > [mailto:piclist-bounces@mit.edu] On Behalf Of =C5ke Neehr > Sent: 2006 May 24, Wed 06:25 > To: piclist@mit.edu > Subject: [PIC]: Code_mystery BRX.asm > > Hello! > > I have been looking at this code for many, many hours now but > I can=B4t understand why only nine (9) bytes will be written in > to the EEprom and the next start from adr 00 again and > writeing over the saved value. > > 00 XX XX XX FF FF FF FF FF > 08 XX XX XX FF FF FF FF FF > 10 XX XX XX FF FF FF FF FF > 18 FF FF FF FF FF FF FF FF > > Transmitter sending: > > header 20xbit1, 1xbit0 > hour 8xbitx, 1xbit1, 1xbit0 > min " " " > sec " " " > chksum " " " > and that works perfect. > > Please help me to solve this problem out! > > Regards > =C5keN > > ; title "Program BRX.ASM" > ; =8Fke Neehr > ; 04 10 14 > ; Function as reading RF signal > > LIST P=3D12F629, R=3DDEC > errorlevel 0,-305 > errorlevel-224 > errorlevel-302 > #include > > ;***** CONSTANT VALUES > hdrcntmin EQU 0x0c ; minimum number of header bits to receive > hdrcntmax EQU 0x10 ; maximum number of header bits to receive > > ; decoder time tolerances are > set at : 0.5T, 1.5T, 2.5T > ; measured in 9xinstr.time > (9usec) counts > > T EQU .39 ; half frame 350 usec (=3D T * 9 usec) > > min_t EQU T/2 ; half frame (T) minimum time > min_2t EQU 3*T/2 ; half frame (T) maximum time and full > frame (2T) minimum time max_2t EQU 5*T/2 ; full frame (2T) > maximum time > > packet_len EQU 3 ; packet length, check var. alloc! > > ; input port bit > #define RXBIT GPIO, 0 > > ; normal decoder logic input > #define SKL btfsc > #define SKH btfss > > > ;***** FLAGS > #define IF_SHORT flags, 0 > #define FIRST_HALF flags, 1 > #define HEADER flags, 2 > #define VALID flags, 7 > > if_short_val EQU 1 ; bit value of IF_SHORT flag > first_half_val EQU 2 ; bit value of FIRST_HALF flag > > > ;***** VARIABLE DEFINITIONS > CBLOCK 0x20 > > ticks ; reset value > bitcnt > tmrval ; timer value > bt ; receive byte buffer > flags ; decode logic status > btcnt ; byte counter > > mrx_buffer0 > mrx_buffer1 ; receive packet buffer > mrx_buffer2 > mrx_buffer3 ; receive buffer, checksum > wait > waithi ; delay value > BCD ; convert to decimal > envar ; to reset > > ENDC > > __CONFIG _MCLRE_OFF & _CP_OFF & _CPD_OFF & > _INTRC_OSC_CLKOUT & _WDT_OFF & _PWRTE_ON & _BODEN_OFF > > > > > > > PAGE ; 4 Mhz INTRC_OSC > > org 0x00 > > init bcf STATUS, RP0 > movlw ticks+1 > movwf FSR > movlw envar-ticks-1 > movwf ticks > clrvar clrf INDF > incf FSR, F > decfsz ticks, F > goto clrvar > clrf GPIO > clrf STATUS > movlw 0x07 > movwf CMCON > bsf STATUS, RP0 > clrf VRCON > movlw 0x7F > movwf EEADR > movlw 0x03 ; prescaler 1:16 > movwf OPTION_REG > movlw 0x09 > movwf TRISIO > movlw 0x80 > movwf OSCCAL ; GPIO,0 3 input > bcf STATUS, RP0 > clrf INTCON > goto loop > > > loop call mrx_receive ; receive > andlw 0xff > bnz loop > call mrx_chk_buf > andlw 0xff > bnz loop > call print > goto loop > > > > mrx_receive ; receive a full > manchester-encoded packet > s3 ; set flags: first_half=3D1, if_short=3D0 > bsf FIRST_HALF > s4 bcf IF_SHORT > > s5 ; init before the received packet > > ; set FSR to buffer start movlw > mrx_buffer0 movwf FSR > ; set byte counter > movlw (packet_len+1) ; bytes / packet > movwf btcnt > ; set header receive mode bsf HEADER > clrf bitcnt ; counting bit1-s in this mode > > s2 ; wait for a pulse > SKH RXBIT > goto s2 > > s6 ; wait for end of (short) > pulse up to min_2t > clrf tmrval > s6_w SKH RXBIT > goto s7 ; goto s7 at end of pulse > > incf tmrval, F > nop > movlw min_2t > subwf tmrval, W > btfss STATUS, C > goto s6_w > > ; timeout, exit > retlw 1 ; illegal startbit > > s7 ; start timer > clrf tmrval > > s8 ; if (if_short & rxbit) goto s9 > ; if (!if_short & !rxbit) goto s9 > ; goto s10 > > btfsc IF_SHORT > ; if_short =3D 1 goto s8_ss1 > > s8_ss0 ; if_short =3D 0 > SKL RXBIT > goto s10 ; rxbit =3D 1, goto s10 > > s9_ss0 ; if (timer > max_2t) > exit - else goto s8 > movlw max_2t > subwf tmrval, W > btfsc STATUS, C > retlw 2 ; signal too long > > incf tmrval, F > goto s8_ss0 > > s8_ss1 ; if_short =3D 1 > SKH RXBIT > goto s10 ; rxbit =3D 0, goto s10 > > s9_ss1 ; if (timer > max_2t) > exit - else goto s8 > movlw max_2t > subwf tmrval, W > btfsc STATUS, C > retlw 2 ; signal too long > > incf tmrval, F > goto s8_ss1 > > s10 ; invert if_short > movlw if_short_val > xorwf flags, F > > s11 ; if (timer < min_t) exit > movlw min_t > subwf tmrval, W > btfss STATUS, C > retlw 3 ; signal too short > > s12 ; if (timer < min_2t) goto s14 > movlw min_2t > subwf tmrval, W > btfss STATUS, C > goto s14 > > s13 ; if (first_half =3D 0) goto > s16 - else exit > btfss FIRST_HALF > goto s16 > retlw 4 ; no mid-frame transition/out of sync > > s14 ; invert first_half > movlw first_half_val > xorwf flags, F > > s15 ; if (first_half =3D 1) goto 7 > btfsc FIRST_HALF > goto s7 > > s16 ; if_short is a decoded > bit. Handle here > btfss HEADER > goto s16_not_header > > ; header receiving mode btfss > IF_SHORT goto s16_header_end > > ; header bit is 1 > btfss bitcnt, 4 ; inc up to 16 > incf bitcnt, F ; 16 is enough... > > #ifdef NOMAXHDR > ; test for max header length > movlw hdrcntmax subwf bitcnt, W btfss STATUS, C #endif > goto s7 ; loop back > retlw 9 ; header too long > > s16_header_end ; header ends > indicated by a 0 > bcf HEADER > > ; test for min header length > movlw hdrcntmin subwf bitcnt, W btfss STATUS, C > retlw 0x0a ; header too short (0x0a) > > next_byte movlw 0x0a > movwf bitcnt > goto s7 ; loop back > > s16_not_header ; receiving bytes > decf bitcnt, F > bz s16_s4 ; if (bitcnt =3D 0) check for a byte-sep 1 > > ; if (bitcnt =3D 1) check for a > byte-separator 0 movlw 1 xorwf bitcnt, W bnz s16_s2 > > ; test for a byte separator 1 > btfsc IF_SHORT goto s7 > retlw 7 ; byte-ending 1 not present > > s16_s2 ; bit is data > > rrf flags, W > rlf bt, F > goto s7 > > s16_s4 ; check for a byte-separator 0 > btfsc IF_SHORT > retlw 8 ; byte-ending 0 not present > > ; OK, received byte is sane, > store in buffer movf bt, W movwf INDF incf FSR, F > > decfsz btcnt, F > goto next_byte > > retlw 0 ; OK, buffer received > > ; buffer checking is not done > automatically! > ; if returned value is 0, call > mrx_chk_buf to check > > > mrx_chk_buf ; check buffer > sanity by chksum > movlw mrx_buffer0 > movwf FSR > movlw (packet_len+1) ; number of bytes with the chksum byte > movwf btcnt > movlw 0xff > movwf bt ; used as sum register > > chk0 movf INDF, W > ; fast CRC-8 algorithm with > poly x^8+x^5+x^4+1 > ; executes in 23 cycles per > update xorwf bt,f clrw btfsc bt,7 xorlw 0x7a btfsc bt,6 xorlw > 0x3d btfsc bt,5 xorlw 0x86 btfsc bt,4 xorlw 0x43 btfsc bt,3 > xorlw 0xb9 btfsc bt,2 xorlw 0xc4 btfsc bt,1 xorlw 0x62 btfsc > bt,0 xorlw 0x31 movwf bt > > incf FSR, F > decfsz btcnt, F > goto chk0 > ; correct checksum must be > zero movf bt, W bnz chk_err > retlw 0 ; result is in Z > chk_err retlw 0x0c ; checksum error > return > > > print movf mrx_buffer0, W > andlw 0x3F > call BinBCD > movf BCD, W > call EEWrite > call delay > movf mrx_buffer1, W > andlw 0x3F > call BinBCD > movf BCD, W > call EEWrite > movf mrx_buffer2, W > andlw 0x3F > call BinBCD > movf BCD, W > call EEWrite > bsf STATUS, RP0 > movlw 0x05 > addwf EEADR > bcf STATUS, RP0 > call delay > return > > BinBCD > clrf BCD > again addlw -10 > btfss STATUS, C > goto swapBCD > incf BCD > goto again > > swapBCD addlw 10 > swapf BCD > iorwf BCD > return > > > EEWrite > bsf STATUS, RP0 > movwf EEDATA > incf EEADR > bsf EECON1, WREN > movlw 0x55 > movwf EECON2 > movlw 0xAA > movwf EECON2 > bsf EECON1, WR > W1 btfsc EECON1, WR > goto W1 > clrf EEDATA > bcf STATUS, RP0 > return > > > delay movlw 0x01 > movwf wait > movlw 0x09 > movwf waithi > decfsz wait, F > goto $ -1 > decfsz waithi, F > goto $ - 3 > return > > > end > > > > -- > http://www.piclist.com PIC/SX FAQ & list archive View/change > your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist