Newbie needing help on 16F84

Discussion in 'Embedded Systems and Microcontrollers' started by alldend, Apr 17, 2008.

  1. alldend

    Thread Starter New Member

    Apr 17, 2008
    3
    0
    hey everyone

    my knowledge on MPLAB is pretty rudimentary but i do know how to setup projects.
    My problem is however that i have no idea what i need to write to solve the following problem!!

    Use port B of the PIC16F84A as an output port, write a simple program to control 8
    LEDS to generate the binary-equivalent of the following decimal numbers:
    119, 76, 14, 55 & 99
    Use a switch as an input to read the status of bit 0 of port A, write a program to switch
    all odd LEDS on (starting with most right LED as number 0) through port B upon
    detecting the switch closure.
    Using two switches and 7 LED write a program such that when switch 1 is pressed on 1​

    LED comes ON permanently, and the next 2 LEDs come ON for 2 seconds. When
    switch 2 is pressed on, the 2 LED comes ON for 1 second followed by turn off of all
    LED.
    PIC Trainer Board

    Any help given on this would be greatly appreciated! feel free to contact me directly as i happily accept any advice!

    thanks

    David​
     
  2. Reshma

    Active Member

    Mar 11, 2007
    54
    0


    Are these Part of the same Program or you have to write 3 different LED based programs?

    I am assuming the latter. Here are my suggestions for your programs:

    1. In the first program you have to display certain decimal numbers on PortB where the LEDs are connected. Configure PortB as output and one pin of PortA as input (you may connect a push/press button here). Write a program which displays the decimal numbers one after the other each time you press the push button.

    2. The circuit connection remains the same here only the program needs to be slightly modified. There are 2 switch states here: ON/OFF. Write a conditional branching code in which the required bit pattern (even/odd LEDs turning ON) is loaded onto PortB when the switch is pressed or unpressed.

    3. Here you will have to manipulate individual bits of PortB. Flashing LEDs can be done by writing suitable delay subroutines within the code.

    If you can show us the code you have written, we can help you furthur.​
     
  3. alldend

    Thread Starter New Member

    Apr 17, 2008
    3
    0
    this is the code i have so far
    sorry but i have no idea what's going on where!!

    ;Date: 21st Feb 2008
    ;This is my first PIC Program
    ;Title: This is a program to set all bits of PortB to status high
    ;Declaration of Processor and Configurations
    PROCESSOR 16f84
    #include "p16f84.inc"

    __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

    ;Start the program at memory address 00H
    ORG 0x00
    goto Main
    ORG 0x04
    goto Main
    #include "NEWMACR.inc"
    #include "delay_macro.inc"

    Main
    ;Select Bank 1
    BANK1
    ;PortB is set as an output port
    PORTBOUT

    ;select Bank 0 (accessing PortB)
    BANK0

    Loop
    movlw 0x00 ;Data to clear all bits of PortB
    movwf PORTB ;Send data to PortB
    movlw 0xFF ;Data to set all 8 bits of PortB to high
    movwf PORTB ;send data to PortB
    goto Loop

    End
     
  4. Neena

    New Member

    Apr 22, 2008
    1
    0
    give delay between you make any changeover on portB
     
  5. Caveman

    Active Member

    Apr 15, 2008
    471
    0
  6. alldend

    Thread Starter New Member

    Apr 17, 2008
    3
    0
    thanks that website looks helpful

    but any further hints are welcomed :-D
     
  7. ex-navy

    New Member

    Apr 22, 2008
    3
    0
    my knowledge on MPLAB is pretty rudimentary but i do know how to setup projects.
    My problem is however that i have no idea what i need to write to solve the following problem!!

    Use port B of the PIC16F84A as an output port, write a simple program to control 8
    LEDS to generate the binary-equivalent of the following decimal numbers:
    119, 76, 14, 55 & 99

    This is part 1:

    PORTB is an 8 bit wide port.

    Writing to PORTB is via the TRISB register. If you write all 1's this means all pins on PORTB become inputs.

    Writing all 0's to TRISB mean all outputs.

    movlw b'00000000'
    movwf TRISB ; PORTB are all outputs

    Now, if you have your LED's connected with the anodes (+) soldered to the pins, you would need a 1 on that pin to light the associated LED.

    If there is a resistor then the cathodes are connected, you need to set that pin low (0)

    Since you need to represent the number 119 in binary, it would be 1110111

    BSF PORTB, 0 ; Set PORTB bit 0 on (1)
    BSF PORTB, 1; Set PORTB bit 1 on (1)


    Use a switch as an input to read the status of bit 0 of port A, write a program to switch all odd LEDS on (starting with most right LED as number 0) through port B upon detecting the switch closure.

    Ok, here you have to set PORTA, bit 0 as an input. Let's make the rest inputs too.

    movlw b'11111111' ; move literal binary value into the w register
    movwf TRISA ;move contents of w in the F register TRISA, all inputs

    ; All PORTB pins as outputs

    movlw b'00000000'
    movwf TRISB ; Make all

    With a switch connected to pin 0 of PORTA, a switch will either give a 0 or a 1 condition. Depending on your set up.

    Let's assume your switch will give a 5 volt (1) when pressed.

    An instruction we use on that pin is BTFSS - Bit Test in File Skip if Set.

    In other words, if the pin we are assigning this instruction has a value of Set (a 1) skip and go to the next instruction.

    BCF which is Bit Clear F, meaning send a 0 to that particular bit
    BSF is Set Bit F, meaning send a 1 to that particular bit

    So something like this:

    Begin BTFSS PORTA,0 ; if a 1 is present, skip and go to next instruction
    GOTO BEGIN
    BSF PORTB,0 ; on
    BSF PORTB,3 ; on
    BSF PORTB,5 ; on.........etc etc

    So, if the switch is open, the next instruction is executed. If it is a zero, the condition loops with the GOTO BEGIN statement.



    Using two switches and 7 LED write a program such that when switch 1 is pressed on 1
    LED comes ON permanently, and the next 2 LEDs come ON for 2 seconds. When​

    switch 2 is pressed on, the 2 LED comes ON for 1 second followed by turn off of all
    LED.
    PIC Trainer Board

    You can use two examples of above switches.

    A delay can be produced by the TMRO register.

    DELAY clrf tmr0
    LOOP movf tmr0, w

    etc etc​
     
Loading...