Help.. Simple LED Project

Discussion in 'Embedded Systems and Microcontrollers' started by nikkzzz05, Oct 19, 2012.

  1. nikkzzz05

    Thread Starter New Member

    Oct 19, 2012
    4
    0
    good day, we need a simple program for pic16f84a, the requiurements are, there should be at 2 input and output. The input are coming from the tact switch. If the tact switch is press, the LED's should lit up, and if the second switch is press the delay of the LED sequence should speed up. We are using Pic Basic plus for the software. The problem is, our prof did not teach us to code for pic16f84a, he just teach us to do the pic16f84a programmer and the developer. It's just a simple program for you guys, but for us, who do not have knowledge in it, it so difficult. I hope you could help us. Thank you in advance..
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Sounds like someone wants us to do their homework assignment.

    If you know how to program the pic16f84a then you should know how to program just about any PIC for a simple program like that.

    Check your datasheet. Compare the one chip to the other.

    Start small like simply turning on an LED. Then add the code for the tact switch.

    BTW You said: "our prof did not teach us to code for pic16f84a, he just teach us to do the pic16f84a"

    So he did teach you to program the chip that you have.
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    And after you have check your datasheet and tried to code something, if you are still stuck, then and only then ask more questions.
     
  4. nikkzzz05

    Thread Starter New Member

    Oct 19, 2012
    4
    0
    he just teach us to do the programmer, the hardware that load the program into the pic, and the developer to test the program.he did not teach us the syntax use in PicBasic and how to code it.ok, Ill try my best to code...thank you for your response
     
    Last edited: Oct 20, 2012
  5. nikkzzz05

    Thread Starter New Member

    Oct 19, 2012
    4
    0
    i forget to include, we have a sample program that has 2 inputs, given by our prof. 1 for the speed of sequence of the LED, and 1 for the, i think if press the LED will lit up. The problem here, is when we test it in the developer, nothing happens. so what our prof did is, he revise the code, he erase the code for the switches and speed, and after testing it, it worked. I think there is a problem in the code for the switch. The compiler use in this program is PicBasic Plus. here is the code with switches.

    Code ( (Unknown Language)):
    1.  
    2. 'OPTIMISER_LEVEL = 6                                      'SET FOR MAXIMUM OPTIMISER LEVEL
    3.      Device = 16F84A
    4.               XTAL = 4
    5.               TRISB = %00000000                           'SET PORT B TO ALL OUTPUT
    6.               TRISA = %00000011                            'I THINK THIS IS TO SET 2 PORTS FROM PORT A TO INPUT
    7.       Symbol Button1 PORTA.0                              'push button
    8.        Symbol speed PORTA.1                                'push button
    9.      Dim sw as Byte
    10.      Dim sp as word
    11.              sw = 1
    12.              sp = 200
    13.              PORTB = 0
    14.       Delayms 50
    15.  
    16. Main:
    17.      if Button1 = 0 then
    18.           sw = sw + 1
    19.           delayms 50
    20.      end if
    21.      if speed = 0 then
    22.           sp = sp - 25
    23.                 if sp = 0 then
    24.                       sp = 200
    25.        end if
    26.  
    27.     if sw = 1 then
    28.           PORTB = %00000011
    29.           Delayms sp
    30.           PORTB = %11000011
    31.           Delayms sp
    32.           PORTB = %11001111
    33.           Delayms sp
    34.            PORTB = %11111111
    35.           Delayms sp
    36.           PORTB = %00000000
    37.           Delayms sp
    38.        Goto main
    39. end
    40.  
    the only part. that i understand is the if sw = 1 then the codes. can you pls help me to debug this program? thank you very much
     
    Last edited by a moderator: Oct 20, 2012
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Please use capital letter at the start of you sentences. It makes it easier to read.

    Someone wasn't listening in class. :)

    Are you certain everything is hooked up correctly? Where is your schematic?

    As I said in a previous post start simple. I am not familiar with Pic Basic so there may be errors but this should get you started.

    Code ( (Unknown Language)):
    1.  
    2. 'OPTIMISER_LEVEL = 6                                      'SET FOR MAXIMUM OPTIMISER LEVEL
    3.      Device = 16F84A
    4.               XTAL = 4
    5.               TRISB = %00000000                           'SET PORT B TO ALL OUTPUT
    6.  
    7.  
    8. Main:
    9.     DelayMs 100
    10.     PortB = 255   'You might want to use LatchB here see if that works
    11.     DelayMs 100
    12.     PortB = 0   'You might want to use LatchB here see if that works
    13.     Goto Main
    14.  
    15.  
    If I coded this correctly, it should flash all of the LEDs on PortB on and off every 100 ms.
     
  7. nikkzzz05

    Thread Starter New Member

    Oct 19, 2012
    4
    0
    Thank you very i much, Ill start with this..
     
Loading...