RC RC receiver input into PIC16f627 to turn LED on

Discussion in 'The Projects Forum' started by vane, May 1, 2009.

  1. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    Basically, what i would like help on is the simple logic behind how you go about measuring 1ms - 2ms pulses every 20ms. I would preferably need help with assembly as that is the program i am currently using

    At the moment I only know how to do it with just one push button

    Code ( (Unknown Language)):
    1. EFFECT_1    BTFSC   PORTA,SW1
    2.         GOTO    EFFECT_1
    3. E1      MOVLW   B'00100000' ;
    4.         MOVWF   PORTB
    5.         CALL    DELAY_ROUTINE
    6.         MOVLW   B'00110000' ;
    7.         MOVWF   PORTB...
    8.        
    Any help would be greatly appreciated.
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Check out This site

    It has lots of information on using a PIC as a channel mixer, including source code.
     
  3. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    I have just tried an example on the internet but it wont flash an LED. How do you know if your chip has burnt out?

    EDIT: No, it hasn't burnt out, i think i have a faulty DIL socket on my experiment board

    Thanks so much for that web link! i will examine it thoroughly in the morning!
     
    Last edited: May 1, 2009
  4. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    Anyone know why i cant call my subroutines in this code?

    Code ( (Unknown Language)):
    1. ;Constants
    2.  
    3. 08h equ C8h     ;Set COUNT1 number (200)
    4. 09h equ Ah      ;Set COUNT2 number (10)
    5. STATUS  equ 03h                 ;Address of the STATUS register
    6. TRISA   equ 85h                 ;Address of the tristate register for port A
    7. PORTA   equ 05h                 ;Address of Port A
    8. COUNT1  equ 08h                 ;First counter for delay loops
    9. COUNT2  equ 09h                 ;Second counter for delay loops
    10.  
    11. ;Port Setup
    12.  
    13.     bsf STATUS,5    ;Bank 1
    14.     movlw   01h     ;Send to W
    15.     movwf   TRISA       ;Send w to TRISA
    16.     bcf STATUS,5    ;Bank 0
    17.  
    18. ;Check if it is jumpered
    19.  
    20. Start   movlw   01h
    21.     movwf   PORTA
    22.  
    23.     BTFSC   PORTA,0     ;see if it is high
    24.  
    25.     call    1msDelay
    26.  
    27. ;1ms delay
    28.  
    29.     call    1msDelay
    30.  
    31. ;Now switching to low for 20ms pulse
    32.  
    33.     movlw   00h
    34.     movwf   PORTA
    35.  
    36. ;20ms Pulse
    37.  
    38. ROUTINE COUNT   equ 20
    39. LABEL21 decfsz  COUNT,1
    40.     Goto    LABEL21
    41.    
    42. ;Restart
    43.  
    44.     goto    Start
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51. ;Subroutines;
    52.  
    53.  
    54. 1msDelay
    55.  
    56. Loop1   decfsz  COUNT1,1     ;This second loop keeps the LED
    57.     goto    Loop1              ;turned off long enough for us to
    58.     decfsz  COUNT2,1      ;see it turned off
    59.     goto    Loop1              ;
    60. return
    Apparently there are 10 errors in this, i can't find them :s
     
    Last edited: May 3, 2009
  5. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    Hello,

    Is a label not supposed to have a semicolon ":" behind it?
    So use,
    1msDelay: as label (also with other labels used).

    Greetings,
    Bertus
     
  6. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901

    I use MPLAB IDE and no colon (or semicolon) is used after labels. The semicolon sets off comments.

    I have a very similar program that works. It would be helpful if Vane would give more detail about how he knows it is not working? For example, is it not compiling, can he step through it, what errors is he getting, and so forth.

    John
     
  7. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901
    Here is a screen print of a portion of the code. Sorry for the fuzziness, I wanted to use the screen print so the exact format and colors would be preserved. Note the subroutine calls and returns (retlw).


    [​IMG]

    John
     
  8. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901
    Ah, your "return" is in the wrong column. Tab it over one. Also, my compiler complains when I use "return", but still works, as I recall. Use "retlw 0"

    John
     
  9. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    Hello John,

    You are right, the return is in the "label colum".

    Greetings,
    Bertus
     
  10. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    Right done that, but that hasn't stopped it saying any other of the errors

    I am just using Notepad to write it and using MPASMWIN to compile
     
  11. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    Hello,

    Can you post the .lst and the .err file generated by MPASM?
    In this file there are the results and errors listed.

    Greetings,
    Bertus

    PS did you already have a look ath the MPASM manual?
    http://gputils.sourceforge.net/33014g.pdf
     
  12. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901
    What are the other errors?

    Everyone has his own preference. I have tried notepad, but get some dumb errors. MPLAB helps in format and spelling. If the instruction is wrong, it won't change to blue and so forth.

    John
     
  13. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    here they are
     
  14. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901
    Here are a couple of quick obserbvations:

    1) Labels must begin with an alpha character or underscore. That takes care of some of the errors.

    2) At least one error was simple misspelling.

    Try fixing those and see what happens.

    John
     
  15. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    For some reason it does not look like it accepts:-

    Code ( (Unknown Language)):
    1. 08h equ C8h     ;Set COUNT1 number (200)
    2. 09h equ Ah      ;Set COUNT2 number (10)
    After this it has 1 more error
     
  16. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901
    I think that is the wrong way to put a value into a register. Go to the code I posted and look at the section beginning Dly_120.

    In other words, your equates should look something like:

    d1 equ 08h
    d2 equ 09h

    Then in your code you will have something like:
    Code ( (Unknown Language)):
    1.  
    2.        clrwdt           ; it's a good idea to clear the wdt
    3.        movlw     c8h     ;  puts d'200 in w
    4.        movwf     d1  ;puts the value in w into the register you have  defined for d1, namely 08h
    5.  
    PS: Sorry for the lousy looking code. I haven't got the knack of writing it in Notepad and posting with the code tags.

    John
     
  17. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    So would that be alright posted in the port setup section?
     
  18. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901
    Where you put it depends on how you are going to use it. I just set up d1, d2, d3, etc. in the equates. Then when I need a delay, I load the correct values in each register. That is, those few registers take care of all of my delays.

    I use a Delay Code Generator on the Internet to calculate nested delay loops. That generator uses d1, etc., and I saw no reason to change. I just cut and paste, then tweak using the simulator and stopwatch functions, if needed. However, for what I was doing, it was close enough ±2 cycles.

    John

    Edit: Here's a link to the code generator: http://www.piclist.com/techref/piclist/codegen/delay.htm
     
  19. vane

    Thread Starter Active Member

    Feb 28, 2007
    181
    0
    haha, i went through all the workings out! working out if it has a 20mhz clock, 1 millisecond is 2000 cycles!
     
  20. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,689
    901
    With a PIC, a cycle is f/4 or 1/5 x10E-6 seconds per cycle with a 20 MHz clock. Thus, 5000 cycles x 1/5 x10E-6 = 0.001 seconds.

    John
     
Loading...