Your own firmware / Twój własny firmware

HAPCAN installation tips and troubleshooting when assembling, running and configuring devices.
Rozwiązywanie problemów z instalacją HAPCAN, budową, uruchamianiem i konfiguracją urządzeń.

Your own firmware / Twój własny firmware

Postby Jacek on 06 Jun 2009 19:51

Many of you ask me if it is possible to write your own code for universal module UNIV 1.0 or processor UNIV 1.0 (CPU). In theory it should be possible. Here I am going to explain how to do so.
What will be needed:
There is not needed any hardware programmer.

At the moment please have a look at memory organization of UNIV 1.0 module and processor UNIV 1.0 (CPU)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Wielu z was pyta mnie czy możliwe jest napisanie własnego kodu dla modułu UNIV 1.0 i procesora UNIV 1.0 (CPU). Teoretycznie nie widzę problemu. Tutaj zamierzam podać informacje jak należy się do tego zabrać.
Przede wszystkim co będzie potrzebne:

Nie będzie potrzebny żaden programator hardware-owy.

Proszę spojrzeć na dane o zarządzaniu pamięcią w module UNIV 1.0 module i procesorze UNIV 1.0 (CPU).
Jacek
 
Posts: 96
Joined: 17 Feb 2007 18:00
Location: London

Code Converter / Konwerter Kodu

Postby Jacek on 17 Jun 2009 22:53

The Code Converter has been created. It can be downloaded here http://siwilo.com/hapcan/devices/diy/hapcanco.exe
There is also a source code template file http://siwilo.com/hapcan/devices/diy/template.asm

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Powstał Konwerter Kodu. Może być pobrany tutaj http://siwilo.com/hapcan/devices/diy/hapcanco.exe
Do pobrania jest również wzorzec pliku dla kodu źródłowego http://siwilo.com/hapcan/devices/diy/template.asm
Jacek
 
Posts: 96
Joined: 17 Feb 2007 18:00
Location: London

Firmware template / Wzorzec firmware

Postby Jacek on 18 Jun 2009 22:49

Code: Select all
;******************************************************************************
;               HAPCAN Home Automation Project
;               Website: http://siwilo.com/hapcan/devices/diy
;******************************************************************************
;    Filename:                         template.asm
;    Firmware version:                 UNIV 1.0.255.X revision Y                   ; User can chose firmware version from
        #define FIRMVER    .255        ;X user firmware version (.00 - .255)       ; numbers between 0 and 255, and
        #define FIRMREV    .65535      ;Y user firmware revision (.00 - .65535)    ; firmware revision from numbers 0-65535
;    Note:
;       This is a template file
;******************************************************************************

;******************************************************************************
;*** NEEDED DEFINITIONS *******************************************************    ; Do not change anything in this section
;******************************************************************************
      LIST P=18F2580               ;directive to define processor
      #include <P18F2580.INC>      ;processor specific variable definitions
   ORG      0x001000               ;firmware version
      DB FIRMVER,FIRMREV/.256,FIRMREV-(FIRMREV/.256*.256)
;******************************************************************************
;*** MOVED VECTORS ************************************************************    ; Do not change anything in this section
;******************************************************************************
;PROGRAM RESET VECTOR
   ORG      0x001020
      goto   Main
;PROGRAM HIGH PRIORITY INTERRUPT VECTOR
   ORG      0x001030
      goto   HighInt
;RECEIVED LOW PRIORITY INTERRUPT VECTOR
   ORG      0x001040
      goto   LowInt
;******************************************************************************
;*** YOUR CODE ****************************************************************
;******************************************************************************
   ORG      0x001050                                                               ; Your code must start above this address.
;********************************
;*** HIGH PRIORITY INTERRUPT ****
;********************************
HighInt:                                                                           ; If you are using high priority interrupt
      ;your own code                                                               ; put procedure here which can handle this
   retfie                                                                          ; event

;********************************
;*** LOW PRIORITY INTERRUPT *****
;********************************                                                  ; Low priority interrupt is responsible for
LowInt:                                                                            ; receiving messages from HAPCAN bus
      ;your own code                                                               ; Put procedure here which reads received
   return                                                                          ; message from RAM memory
                                                                                   ; (addresses 0x020 - 0x02D)
;********************************
;*** MAIN PROGRAM ***************
;********************************
Main:
      ;your own code                                                               ; This is a space for main program code
Loop:
      clrwdt                                                                       ; Instruction to clear watchdog timer
   bra      Loop                                                                   ; must be used at least every 2s.

;******************************************************************************
;*** END OF MAIN PROGRAM ******************************************************
;******************************************************************************
      END
Jacek
 
Posts: 96
Joined: 17 Feb 2007 18:00
Location: London

The source code example 1 / Przyklad 1 kodu źródłowego

Postby Jacek on 18 Jun 2009 23:11

The application toggles monostable relay every 1s.

Ten program zmienia stan przekaźnika co 1s.

Code: Select all
;******************************************************************************
;               HAPCAN Home Automation Project
;               Website: http://siwilo.com/hapcan/devices/diy
;******************************************************************************
;    Filename:                          example1.asm
;    Firmware version:                  UNIV 1.0.255.X revision Y
        #define FIRMVER    .01          ;X user firmware version (.00 - .255)
        #define FIRMREV    .00          ;Y user firmware revision (.00 - .65535)
;    Note:
;       The application toggles monostable relay every 1s.
;******************************************************************************

;******************************************************************************
;*** NEEDED DEFINITIONS *******************************************************
;******************************************************************************
      LIST P=18F2580               ;directive to define processor
      #include <P18F2580.INC>      ;processor specific variable definitions
   ORG      0x001000               ;firmware version
      DB FIRMVER,FIRMREV/.256,FIRMREV-(FIRMREV/.256*.256)
;******************************************************************************
;*** MOVED VECTORS ************************************************************
;******************************************************************************
;PROGRAM RESET VECTOR
   ORG      0x001020
      goto   Main
;PROGRAM HIGH PRIORITY INTERRUPT VECTOR
   ORG      0x001030
      goto   HighInt
;RECEIVED LOW PRIORITY INTERRUPT VECTOR
   ORG      0x001040
      goto   LowInt
;******************************************************************************
;*** YOUR CODE ****************************************************************
;******************************************************************************
   ORG      0x001050
;********************************
;*** HIGH PRIORITY INTERRUPT ****
;********************************
HighInt:
      ;your own code
   retfie

;********************************
;*** LOW PRIORITY INTERRUPT *****
;********************************
LowInt:
      ;your own code
   return

;********************************
;*** MAIN PROGRAM ***************
;********************************
;register definitions                  ; defining easy to use registers name
R0      EQU      H'0000'
R1      EQU      H'0001'
R2      EQU      H'0002'

;procedures
Delay_1s:                              ; this procedure just takes 1s to run
      movlw    .20
      movwf    R0
L3:   movlw    .65
      movwf    R1
L2:   movlw    .255
      movwf    R2
L1:   decfsz   R2
      bra      L1
      decfsz   R1
      bra      L2
      decfsz   R0
      bra      L3
      return
Main:
      movlw    b'11111110'             ; set bit 0 of port C as an output (this is where relay is connected)
      movwf    TRISC
Loop:
      bcf      LATC,0                  ; turn off relay
      call     Delay_1s                ; wait 1s
      bsf      LATC,0                  ; turn on relay
      call     Delay_1s                ; wait 1s
      clrwdt                           ; clear watchdog
   bra      Loop                       ; repeat

;******************************************************************************
;*** END OF MAIN PROGRAM ******************************************************
;******************************************************************************
      END
Jacek
 
Posts: 96
Joined: 17 Feb 2007 18:00
Location: London

The source code example 2 / Przyklad 2 kodu źródłowego

Postby Jacek on 01 Jul 2009 22:36

This example toggles monostable relay every time when module receives any message from node (node,group).

Ten program zmienia stan przekaźnika za każdym razem kiedy urządzenie odbierze jakąkolwiek wiadomość od modułu (node,group).

Code: Select all
;******************************************************************************
;               HAPCAN Home Automation Project
;               Website: http://siwilo.com/hapcan/devices/diy
;******************************************************************************
;    Filename:                          example2.asm
;    Firmware version:                  UNIV 1.0.255.X revision Y
        #define FIRMVER    .02          ;X user firmware version (.00 - .255)
        #define FIRMREV    .00          ;Y user firmware revision (.00 - .65535)
;    Note:
;    Application toggles monostable relay every time when module
;    receives any message from node (node,group)
        #define node       .1           ;defines node (1.1)
        #define group      .1
;******************************************************************************

;******************************************************************************
;*** NEEDED DEFINITIONS *******************************************************
;******************************************************************************
      LIST P=18F2580               ;directive to define processor
      #include <P18F2580.INC>      ;processor specific variable definitions
   ORG      0x001000               ;firmware version
      DB FIRMVER,FIRMREV/.256,FIRMREV-(FIRMREV/.256*.256)
;******************************************************************************
;*** MOVED VECTORS ************************************************************
;******************************************************************************
;PROGRAM RESET VECTOR
    ORG      0x001020
        goto   Main
;PROGRAM HIGH PRIORITY INTERRUPT VECTOR
    ORG      0x001030
        goto   HighInt
;RECEIVED LOW PRIORITY INTERRUPT VECTOR
    ORG      0x001040
        goto   LowInt
;******************************************************************************
;*** YOUR CODE ****************************************************************
;******************************************************************************
    ORG      0x001050
;********************************
;*** HIGH PRIORITY INTERRUPT ****
;********************************
HighInt:
        ;your own code
    retfie

;********************************
;*** LOW PRIORITY INTERRUPT *****
;********************************
LowInt:
        movlw   node              ;is this expected node?
        xorwf   NODE,W
        bnz     ExitLowInt        ;exit if not
        movlw   group             ;is this expected group?
        xorwf   GROUP,W
        bnz     ExitLowInt        ;exit if not
        btg     LATC,0            ;toggle bit
ExitLowInt   
    return

;********************************
;*** MAIN PROGRAM ***************
;********************************
;definitions
NODE    EQU     H'0023'           ;memory cell where node nr of received message is saved
GROUP   EQU     H'0024'           ;memory cell where group nr of received message is saved

Main:
        movlw   b'11111110'       ;set output on port C, bit 0 where relay is
        movwf   TRISC
Loop:
      clrwdt                      ;clear watchdog

    bra     Loop

;******************************************************************************
;*** END OF MAIN PROGRAM ******************************************************
;******************************************************************************
        END

Jacek
 
Posts: 96
Joined: 17 Feb 2007 18:00
Location: London

The source code example 3 / Przyklad 3 kodu źródłowego

Postby Jacek on 10 Jul 2009 22:15

This is a button node application with functionality identical to UNIV 1.0.1.0

Jest to przykład aplikacji dla modułu przycisk z funkcjonalnością jak UNIV 1.0.1.0

Code: Select all
;******************************************************************************
;               HAPCAN Home Automation Project
;               Website: http://siwilo.com/hapcan/devices/diy
;******************************************************************************
;    Filename:                          example3.asm
;    Firmware version:                  UNIV 1.0.255.X revision Y
        #define FIRMVER    .03          ;X user firmware version (.00 - .255)
        #define FIRMREV    .00          ;Y user firmware revision (.00 - .65535)
;    Note:
;       This is a button node application identical to UNIV 1.0.1.0
;******************************************************************************

;******************************************************************************
;*** NEEDED DEFINITIONS *******************************************************
;******************************************************************************
        LIST P=18F2580                  ;directive to define processor
        #include <P18F2580.INC>         ;processor specific variable definitions
    ORG     0x001000                    ;firmware version
        DB FIRMVER,FIRMREV/.256,FIRMREV-(FIRMREV/.256*.256)
;******************************************************************************
;*** MOVED VECTORS ************************************************************
;******************************************************************************
;PROGRAM RESET VECTOR
    ORG     0x001020
        goto    Main
;PROGRAM HIGH PRIORITY INTERRUPT VECTOR
    ORG     0x001030
        goto    HighInt
;RECEIVED LOW PRIORITY INTERRUPT VECTOR
    ORG     0x001040
        goto    LowInt
;******************************************************************************
;*** YOUR CODE ****************************************************************
;******************************************************************************
    ORG     0x001050
;********************************
;*** HIGH PRIORITY INTERRUPT ****
;********************************
HighInt:
        ;your own code
        retfie

;********************************
;*** LOW PRIORITY INTERRUPT *****
;********************************
LowInt:
        ;response?
        btfsc   RXBITS,0                ;check if it is response
    return                              ;yes, so exit
        ;is this Status Request (0x108 or 0x109)?
        movlw   0x10
        xorwf   RXFRAME,W
        bz      $ + 4
        return     
        movlw   0x80                    ;request to group
        xorwf   RXBITS,W
        bnz     $ + 4      
        bra     CheckGroupDestination
        movlw   0x90                    ;request to node
        xorwf   RXBITS,W
        bnz     $ + 4
        bra     CheckNodeDestination      
    return       
        ;am I destination of received message?
CheckGroupDestination
        clrf    WREG                    ;check if node nr = 0
        xorwf   RXD2,W
        bz      $ + 4
    return
        clrf    WREG                    ;check if for all nodes (group nr = 0?)
        xorwf   RXD3,W
        bnz     $ + 4
        bra     ButtonStatus            ;request is for all node s
        movff   0x127,WREG              ;check group nr
        xorwf   RXD3,W
        bz      $ + 4
    return
        bra     ButtonStatus            ;request is for node in this group
CheckNodeDestination
        movff   0x126,WREG              ;check node nr
        xorwf   RXD2,W
        bz      $ + 4
    return
        movff   0x127,WREG              ;check group nr
        xorwf   RXD3,W
        bz      $ + 4
    return
        bra     ButtonStatus            ;request is for this node
        ;send status for each input
ButtonStatus
        movlw   0x01                    ;button 1
        movwf   TXD2
        setf    WREG
        btfsc   R0,0                    ;0-pressed
        clrf    WREG
        movwf   TXD3
        rcall   SendStatus
        movlw   0x02                    ;button 2
        movwf   TXD2
        setf    WREG
        btfsc   R0,1                    ;0-pressed
        clrf    WREG
        movwf   TXD3
        rcall   SendStatus
        movlw   0x03                    ;button 3
        movwf   TXD2
        setf    WREG
        btfsc   R0,2                    ;0-pressed
        clrf    WREG
        movwf   TXD3
        rcall   SendStatus
        movlw   0x04                    ;button 4
        movwf   TXD2
        setf    WREG
        btfsc   R0,3                    ;0-pressed
        clrf    WREG
        movwf   TXD3
        rcall   SendStatus
        movlw   0x05                    ;button 5
        movwf   TXD2
        setf    WREG
        btfsc   R0,4                    ;0-pressed
        clrf    WREG
        movwf   TXD3
        rcall   SendStatus
        movlw   0x06                    ;button 6
        movwf   TXD2
        setf    WREG
        btfsc   R0,5                    ;0-pressed
        clrf    WREG
        movwf   TXD3
        rcall   SendStatus
    return
SendStatus
        movlw   0x30                    ;set frame type
        movwf   TXFRAME
        movlw   0x10
        movwf   TXBITS
        bsf     TXBITS,0                ;response bit
        movff   0x126,TXNODE            ;take idenfifier from copied eeprom (bank 1)
        movff   0x127,TXGROUP
        movlw   b'00001000'             ;length code = 8 bytes
        movwf   TXDLC
        setf    TXD0                    ;unused
        setf    TXD1                    ;unused
        setf    TXD4                    ;unused
        setf    TXD5                    ;unused
        setf    TXD6                    ;unused
        setf    TXD7                    ;unused
        call    Transmit
    return

;********************************
;*** MAIN PROGRAM ***************
;********************************
;DEFINITIONS
R0          EQU     H'0000'             ;last button status register
R1          EQU     H'0001'             ;temporary register
R2          EQU     H'0002'             ;temporary register
;receive buffer
RXFRAME     EQU     H'0021'
RXBITS      EQU     H'0022'
RXNODE      EQU     H'0023'
RXGROUP     EQU     H'0024'
RXDLC       EQU     H'0025'
RXD0        EQU     H'0026'
RXD1        EQU     H'0027'
RXD2        EQU     H'0028'
RXD3        EQU     H'0029'
RXD4        EQU     H'002A'
RXD5        EQU     H'002B'
RXD6        EQU     H'002C'
RXD7        EQU     H'002D'
;transmit buffer
TXFRAME     EQU     H'0031'
TXBITS      EQU     H'0032'
TXNODE      EQU     H'0033'
TXGROUP     EQU     H'0034'
TXDLC       EQU     H'0035'
TXD0        EQU     H'0036'
TXD1        EQU     H'0037'
TXD2        EQU     H'0038'
TXD3        EQU     H'0039'
TXD4        EQU     H'003A'
TXD5        EQU     H'003B'
TXD6        EQU     H'003C'
TXD7        EQU     H'003D'

;ROUTINES
Delay_20ms:
        movlw   0x1A
        movwf   R1   
L2:     movlw   0xFF
        movwf   R2
L1:     decfsz  R2
        bra     L1
        decfsz  R1
        bra     L2
        return
Transmit:
        clrwdt
    ;prepare bits in TXBSIDL
        btfsc   TXBITS,4                ;what is the fourth bit?
        bra     $ + 6                   ;it is 1, so set it in fourth position
        bcf     TXBITS,1                ;it is 0, so clear it in fourth position
        bra     $ + 4
        bsf     TXBITS,1
        bsf     TXBITS,3                ;set EXIDE bit

        movlb   0xF                     ;choose bank 15
TXB2
        btfsc   TXB2CON,3               ;check if TXB2 is free skip if free
        bra     TXB1
        lfsr    FSR2,0xF21              ;point at first register of transmit buffer 2
        call    WriteBuffer
        bsf     TXB2CON,3               ;request trasmission
        movlb   0x0                     ;go back to bank 0
        return
TXB1
        btfsc   TXB1CON,3               ;check if TXB1 is free skip if free
        bra     TXB2
        lfsr    FSR2,0xF31              ;point at first register of transmit buffer 1
        call    WriteBuffer
        bsf     TXB1CON,3               ;request trasmission
        movlb   0x0                     ;go back to bank 0
        return

WriteBuffer:
        lfsr    FSR1,0x031              ;point at first register of source buffer
        movlw   0x0D                    ;read 13 successive registers
WriteBufferLoop:
        movff   POSTINC1,POSTINC2       ;move data from transmit buffer to destination buffer
        decfsz  WREG                    ;all 13 bytes read?
        bra     WriteBufferLoop         ;not yet - read more
    return

Main:
    ;initiate ports
        clrf    LATC                    ;clear PORTC output latch
        movlw   b'00111111'             ;make PORTC pins <0:5> as inputs
        movwf   TRISC      
    ;other
        setf    R0                      ;set last buttons status reg 1-button released

Loop:
        clrwdt
B1      btfss   PORTC,0                 ;check button 1
        bra     Button1_ON
        bra     Button1_OFF
B2      btfss   PORTC,1                 ;check button 2
        bra     Button2_ON
        bra     Button2_OFF
B3      btfss   PORTC,2                 ;check button 3
        bra     Button3_ON
        bra     Button3_OFF
B4      btfss   PORTC,3                 ;check button 4
        bra     Button4_ON
        bra     Button4_OFF
B5      btfss   PORTC,4                 ;check button 5
        bra     Button5_ON
        bra     Button5_OFF
B6      btfss   PORTC,5                 ;check button 6
        bra     Button6_ON
        bra     Button6_OFF
    bra     Loop

Button1_ON:
        call    Delay_20ms
        btfsc   PORTC,0                 ;check button again
        bra     B2
        btfss   R0,0                    ;what was last state? 1-released, 0-pressed
    bra     B2                          ;state was the same
        ;transmit new state
        bcf     R0,0                    ;set new state
        movlw   0x01                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 1"
        setf    TXD3                    ;"0xFF - pressed"
        call    TransmitButton
    bra     B2
Button1_OFF:
        call    Delay_20ms
        btfss   PORTC,0                 ;check button again
        bra     B2
        btfsc   R0,0                    ;what was last state? 1-released, 0-pressed
    bra     B2                          ;state was the same
        ;transmit new state
        bsf     R0,0                    ;set new state
        movlw   0x01                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 1"
        clrf    TXD3                    ;"0x00 - released"
        call    TransmitButton
    bra     B2


Button2_ON:
        call    Delay_20ms
        btfsc   PORTC,1                 ;check button again
        bra     B3
        btfss   R0,1                    ;what was last state? 1-released, 0-pressed
    bra     B3                          ;state was the same
        ;transmit new state
        bcf     R0,1                    ;set new state
        movlw   0x02                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 2"
        setf    TXD3                    ;"0xFF - pressed"
        call    TransmitButton
    bra     B3
Button2_OFF:
        call    Delay_20ms
        btfss   PORTC,1                 ;check button again
        bra     B3
        btfsc   R0,1                    ;what was last state? 1-released, 0-pressed
    bra     B3                          ;state was the same
        ;transmit new state
        bsf     R0,1                    ;set new state
        movlw   0x02                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 2"
        clrf    TXD3                    ;"0x00 - released"
        call    TransmitButton
    bra     B3


Button3_ON:
        call    Delay_20ms
        btfsc   PORTC,2                 ;check button again
        bra     B4
        btfss   R0,2                    ;what was last state? 1-released, 0-pressed
    bra     B4                          ;state was the same
        ;transmit new state
        bcf     R0,2                    ;set new state
        movlw   0x03                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 3"
        setf    TXD3                    ;"0xFF - pressed"
        call    TransmitButton
    bra     B4
Button3_OFF:
        call    Delay_20ms
        btfss   PORTC,2                 ;check button again
        bra     B4
        btfsc   R0,2                    ;what was last state? 1-released, 0-pressed
    bra     B4                          ;state was the same
        ;transmit new state
        bsf     R0,2                    ;set new state
        movlw   0x03                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 3"
        clrf    TXD3                    ;"0x00 - released"
        call    TransmitButton
    bra     B4


Button4_ON:
        call    Delay_20ms
        btfsc   PORTC,3                 ;check button again
        bra     B5
        btfss   R0,3                    ;what was last state? 1-released, 0-pressed
    bra     B5                          ;state was the same
        ;transmit new state
        bcf     R0,3                    ;set new state
        movlw   0x04                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 4"
        setf    TXD3                    ;"0xFF - pressed"
        call    TransmitButton
    bra     B5
Button4_OFF:
        call    Delay_20ms
        btfss   PORTC,3                 ;check button again
        bra     B5
        btfsc   R0,3                    ;what was last state? 1-released, 0-pressed
    bra     B5                          ;state was the same
        ;transmit new state
        bsf     R0,3                    ;set new state
        movlw   0x04                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 4"
        clrf    TXD3                    ;"0x00 - released"
        call    TransmitButton
    bra     B5


Button5_ON:
        call    Delay_20ms
        btfsc   PORTC,4                 ;check button again
        bra     B6
        btfss   R0,4                    ;what was last state? 1-released, 0-pressed
    bra     B6                          ;state was the same
        ;transmit new state
        bcf     R0,4                    ;set new state
        movlw   0x05                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 5"
        setf    TXD3                    ;"0xFF - pressed"
        call    TransmitButton
    bra     B6
Button5_OFF:
        call    Delay_20ms
        btfss   PORTC,4                 ;check button again
        bra     B6
        btfsc   R0,4                    ;what was last state? 1-released, 0-pressed
    bra     B6                          ;state was the same
        ;transmit new state
        bsf     R0,4                    ;set new state
        movlw   0x05                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 5"
        clrf    TXD3                    ;"0x00 - released"
        call    TransmitButton
    bra     B6


Button6_ON:
        call    Delay_20ms
        btfsc   PORTC,5                 ;check button again
        bra     B1
        btfss   R0,5                    ;what was last state? 1-released, 0-pressed
    bra     Loop                        ;state was the same
        ;transmit new state
        bcf     R0,5                    ;set new state
        movlw   0x06                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 6"
        setf    TXD3                    ;"0xFF - pressed"
        call    TransmitButton
    bra     Loop
Button6_OFF:
        call    Delay_20ms
        btfss   PORTC,5                 ;check button again
        bra     B1
        btfsc   R0,5                    ;what was last state? 1-released, 0-pressed
    bra     Loop                        ;state was the same
        ;transmit new state
        bsf     R0,5                    ;set new state
        movlw   0x06                    ;load data to transmit buffer
        movwf   TXD2                    ;"button 6"
        clrf    TXD3                    ;"0x00 - released"
        call    TransmitButton
    bra     Loop

TransmitButton
        movlw   0x30                    ;set frame type
        movwf   TXFRAME
        movlw   0x10
        movwf   TXBITS
        movff   0x126,TXNODE            ;take idenfifier from copied eeprom (bank 1)
        movff   0x127,TXGROUP
        movlw   b'00001000'             ;length code = 8 bytes
        movwf   TXDLC
        setf    TXD0                    ;unused
        setf    TXD1                    ;unused
        ;TXBD2 and TXBD3 are already changed in ButtonX functions
        setf    TXD4                    ;unused
        setf    TXD5                    ;unused
        setf    TXD6                    ;unused
        setf    TXD7                    ;unused
        call    Transmit
    return

;******************************************************************************
;*** END OF MAIN PROGRAM ******************************************************
;******************************************************************************
    END

Jacek
 
Posts: 96
Joined: 17 Feb 2007 18:00
Location: London


Return to Technical Support / Wsparcie techniczne



Who is online

Users browsing this forum: No registered users and 1 guest

cron