Advertisement
Guest User

PIC NEXA LYC Remote controll

a guest
Apr 22nd, 2012
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. List      P=16f690              ; list directive to define processor
  2. #include <p16f690.inc>
  3.              errorlevel -302
  4.             __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
  5.  
  6. ;;;       __config  _FCMEN_OFF& _IESO_OFF& _MCLRE_OFF& _WDT_OFF& _INTOSCIO
  7. ;;; ;
  8. ;;; ;    _FCMEN_OFF           ; -- fail safe clock monitor enable off
  9. ;;; ;    _IESO_OFF            ; -- int/ext switch over enable off
  10. ;;; ;    _BOR_ON              ; default, brown out reset on
  11. ;;; ;    _CPD_OFF             ; default, data eeprom protection off
  12. ;;; ;    _CP_OFF              ; default, program code protection off
  13. ;;; ;    _MCLR_OFF            ; -- use MCLR pin as digital input
  14. ;;; ;    _PWRTE_OFF           ; default, power up timer off
  15. ;;; ;    _WDT_OFF             ; -- watch dog timer off
  16. ;;; ;    _INTOSCIO            ; -- internal osc, RA6 and RA7 I/O
  17. ;;; ;
  18.  
  19. ;;; ;  --< constants >---------------------------------------------------
  20.  
  21.     radix dec
  22.  
  23. clock   equ     8           ; 8 MHz
  24.     cblock  0x20
  25.         d1      ; Define four file registers for the
  26.         d2      ; delay loop
  27.         d3
  28.             d4
  29.     endc
  30.    
  31.     org     0x000
  32.     goto    Init
  33.  
  34. Init:  
  35.     bsf     STATUS,RP1 ; bank 2                          |B2
  36.     clrf    ANSEL      ; turn off ADC pins               |B2
  37.     clrf    ANSELH     ; turn off ADC pins               |B2
  38. ;;;
  39. ;;;    setup 8 MHz INTOSC
  40. ;;;
  41.     bcf     STATUS,RP1 ; bank 0                          |B0
  42.     bsf     STATUS,RP0 ; bank 1                          |B1
  43.     movlw   b'01110000' ; '01110000'                      |B1
  44.     movwf   OSCCON      ;                                 |B1
  45. Stable:        
  46.     btfss   OSCCON,HTS ; osc stable? yes, skip, else     |B1
  47.     goto    Stable     ; test again                      |B1
  48. ;;;
  49. ;;;    setup ports
  50. ;;;
  51.     movlw   0xFF
  52.     movwf   TRISA ; Make PortA all input
  53.     clrf    TRISB ; setup PORT B all outputs        |B1
  54.     clrf    TRISC ; setup PORT C all outputs        |B1
  55.         bcf     STATUS,RP0
  56.  
  57.     ;;  Make sure the "TX" port is OFF
  58.     bcf PORTB,4
  59.    
  60. start: 
  61.     bsf PORTC,0
  62.     call    ldelay
  63.    
  64.     call    set_on_nexa
  65.     call    set_on_nexa
  66.     call    set_on_nexa
  67.     call    set_on_nexa
  68.  
  69.     bcf PORTC,0
  70.     call    ldelay
  71.     goto    start
  72.  
  73. set_on_nexa:
  74.     ;; Sync
  75.     call    sync_nexa
  76.     ;; transmitter id
  77.     call    trans_id
  78.     ;; Group 0
  79.     call    one_nexa
  80.     call    zero_nexa
  81.     ;; Dimmer,On,Off : Dimmer 11
  82.     call    zero_nexa
  83.     call    zero_nexa
  84.     ;; Channel
  85.     call    one_nexa
  86.     call    zero_nexa
  87.     call    one_nexa
  88.     call    zero_nexa
  89.     ;; Button
  90.     call    one_nexa
  91.     call    zero_nexa
  92.     call    one_nexa
  93.     call    zero_nexa
  94.     ;; Dim
  95.     call    zero_nexa
  96.     call    one_nexa
  97.     call    zero_nexa
  98.     call    one_nexa
  99.     call    zero_nexa
  100.     call    one_nexa
  101.     call    zero_nexa
  102.     call    one_nexa
  103.     ;;
  104.  
  105.     ;; Delay 10ms
  106.         call    zero_nexa
  107.     call    Delay_2550
  108.     call    Delay_2550
  109.     call    Delay_2550
  110.     call    Delay_2550
  111.     return
  112.    
  113. sync_nexa:
  114.     bsf PORTB,4
  115.     call    Delay_240
  116.     bcf PORTB,4
  117.     call    Delay_2550
  118.     return
  119.    
  120. one_nexa:
  121.         bsf     PORTB,4
  122.     call    Delay_240
  123.     bcf     PORTB,4
  124.     call    Delay_1270
  125.     return
  126.  
  127. zero_nexa:
  128.     bsf     PORTB,4
  129.     call    Delay_240
  130.     bcf     PORTB,4
  131.     call    Delay_240
  132.     return
  133.    
  134.    
  135. ldelay:
  136.     movlw   5
  137.     movwf   d4
  138.     movlw   250
  139.     call    Delay
  140.     decfsz  d4,f
  141.     goto    $-2
  142.    
  143. Delay:
  144.     movwf   d2
  145. Delay_s:            ; Original from another code, i dont change this, 350us * whatever W contains
  146.     ;; 700 cycles
  147.     movlw   0xE9
  148.     movwf   d1
  149. Delay_0:   
  150.     decfsz  d1, f
  151.     goto    $-1
  152.     decfsz  d2, f
  153.     goto    Delay_s
  154.     return
  155.  
  156.    
  157. Delay_240: 
  158.     ;; 240us
  159.     movlw   0x9F
  160.     movwf   d1
  161. Delay_2:   
  162.     decfsz  d1, f
  163.     goto    Delay_2
  164.     return
  165.    
  166. Delay_1270:
  167.     ;; 1270us
  168.     movlw   0xFB
  169.     movwf   d1
  170.     movlw   0x02
  171.     movwf   d2
  172. Delay_3:   
  173.     decfsz  d1, f
  174.     goto    $+2
  175.     decfsz  d2, f
  176.     goto    Delay_3
  177.     return
  178.  
  179. Delay_2550:
  180.     ;; 2550us this
  181.     movlw   0xE7
  182.     movwf   d1
  183.     movlw   0x04
  184.     movwf   d2
  185. Delay_4:   
  186.     decfsz  d1, f
  187.     goto    $+2
  188.     decfsz  d2, f
  189.     goto    Delay_4
  190.     return
  191.  
  192.     ;; 1010101010 01101010 010110 101001 1001100110 011001 010110
  193. trans_id:
  194.     call    one_nexa
  195.     call    zero_nexa
  196.  
  197.     call    one_nexa
  198.     call    zero_nexa
  199.  
  200.     call    one_nexa
  201.     call    zero_nexa
  202.  
  203.     call    one_nexa
  204.     call    zero_nexa
  205.  
  206.     call    one_nexa
  207.     call    zero_nexa
  208.  
  209.     call    zero_nexa
  210.     call    one_nexa
  211.  
  212.     call    one_nexa
  213.     call    zero_nexa
  214.  
  215.     call    one_nexa
  216.     call    zero_nexa
  217.  
  218.     call    one_nexa
  219.     call    zero_nexa
  220.  
  221.     call    zero_nexa
  222.     call    one_nexa
  223.  
  224.     call    zero_nexa
  225.     call    one_nexa
  226.  
  227.     call    one_nexa
  228.     call    zero_nexa
  229.  
  230.     call    one_nexa
  231.     call    zero_nexa
  232.  
  233.     call    one_nexa
  234.     call    zero_nexa
  235.  
  236.     call    zero_nexa
  237.     call    one_nexa
  238.    
  239.     call    one_nexa
  240.     call    zero_nexa
  241.  
  242.     call    zero_nexa
  243.     call    one_nexa
  244.  
  245.     call    one_nexa
  246.     call    zero_nexa
  247.  
  248.     call    zero_nexa
  249.     call    one_nexa
  250.  
  251.     call    one_nexa
  252.     call    zero_nexa
  253.  
  254.     call    zero_nexa
  255.     call    one_nexa
  256.  
  257.     call    one_nexa
  258.     call    zero_nexa
  259.  
  260.     call    zero_nexa
  261.     call    one_nexa
  262.    
  263.     call    zero_nexa
  264.     call    one_nexa
  265.  
  266.     call    zero_nexa
  267.     call    one_nexa
  268.  
  269.     call    one_nexa
  270.     call    zero_nexa
  271.     return
  272.  
  273.  
  274.  
  275. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement