PDA

View Full Version : Can anyone help a beginner in a struggle?



douglasjam
- 5th May 2005, 16:38
I have been given 2 tasks to do using MPLab and it's all completely new to me so I have no idea how to!

1. The task is to 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 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 LEDs, write a program such that when switch 1 is pressed on 1 LED come on permanently, and the next 2 LEDs come on for 2 seconds. When switch 2 is pressed on, the LED comes on for 1 second followed by turn off of all LED.

so far I have this code...

;Program to flash LEDs connected to portB through input from a switch connected to portA

;Declaration of processor and configuration

PROCESSOR 16f84
#include "p16f84.inc"

__CONFIG _CP_OFF &_WDT_OFF & _PWRITE_ON & _XT_OSC

;**************** Label Definition ********************

INPUT1 EQU 0 ;Push Button Input RA0
INPUT2 EQU 1 ;Push Button Input RA1
INPUT3 EQU 2 ;Push Button Input RA2
INPUT4 EQU 3 ;Push Button Input RA3



ORG 0x00 ;Reset Vector
goto Main ;go to the beginning of the main program
ORG 0x04 ;interrupt vector
goto Main ;go to the beginning of the main program

#include "MakrosV1.inc"

Main

BANK1 ;Select Bank1 where TRISA & TRISB
clrf TRISB ;Clear TRISB
input PORTA, INPUT 1 ;Bit 0 of PORTA is input
input PORTA, INPUT 2 ;Bit 1 of PORTA is input
input PORTA, INPUT 3 ;Bit 2 of PORTA is input
input PORTA, INPUT 4 ;Bit 3 of PORTA is input
BANK0 ;Select BANK0


clrf PORTB ;Clear PORTB

START BTFSC PORTA, INPUT1 ;Test if bit0 of PORTA goes high due to connected button being pressed
GOTO SET1 ;if bit0 is high goto SET1 to set 2 LEDs ON
BTFSC PORTA, INPUT2 ;Test if bit1 of PORTA goes high due to connected button being pressed
GOTO SET2 ;if bit1 is high goto SET2 to set the next 2 LEDs ON
BTFSC PORTA, INPUT3 ;Test if bit2 of PORTA goes high due to connected button being pressed
GOTO SET3 ;if bit2 is high goto SET3 to set the next 2 LEDs ON
BTFSC PORTA, INPUT4 ;Test if bit3 of PORTA goes high due to connected button being pressed
GOTO SET4 ;if bit3 is high goto SET4 to set the next 2 LEDs ON
GOTO START ;Repeat by going to start

SET1 MOVLW b'11000000'
MOVWF PORTB ;First 2 LEDs ON
GOTO START ;Repeat by going to start

SET2 MOVLW b'00110000'
MOVWF PORTB ;Next 2 LEDs ON
GOTO START

SET3 MOVLW b'00001100'
MOVWF PORTB ;Next 2 LEDs ON
GOTO START

SET4 MOVLW b'00000011'
MOVWF PORTB ;Next 2 LEDs ON
GOTO START

END




The next task is...
Use the PIC16C55A, write a program to detect the status of keypad 1, 2 and 3 from the 3x4 keypad switches found on this board. Hence execute the following actions:
Upon sensing a press on keypad 1 set the first 7 segment LED to give even number shapes from 0 to 9 and to generate all hex values above 9. Make the program to execute continuously for 10 times.

So far I have this...
;Program to test a 4x3 keypad. It switches a 7-Segment via port C
;when keypad 1 is pressed.

;Microchip 16C55 is used
;HeaderC55 PORTA & PORTC ARE OUTPUT, PORTB is mixed I/O



;Declarations and microcontroller confirguration

PROCESSOR 16C55
#include P16C5X.INC

__CONFIG _CP_OFF & _WDT_OFF &_XT_OSC

Cblock 0x0c ;Beginning of RAM GPR Register
endc ;No Variables

;Program memory structure

ORG 0x00 ;Reset Vector
goto Main ;After reset direct PC to "Main" address

ORG 0x04 ;Interrupt Vector
goto Main ;No interrupt routine, direct PC to "Main" address


Main:
BSF STATUS,5 ;turns to bank 1
MOVLW b'00000000' ;PORTA is OUTPUT
TRIS PORTA

MOVLW b'00000000' ;PORTC is OUTPUT
TRIS PORTC

MOVLW b'00000000' ;PORTB is mixed I/O
TRIS PORTB
BCF STATUS,5 ;Return to Bank0
CLRF PORTA ;Clear PORTA
CLRF PORTB ;Clear PORTB
CLRF PORTC ;Clear PORTC



;Program begins here

C1 BCF PORTB,0 ;Clear bit0 of PORTB
BSF PORTB,1 ;Set bit1 of PORTB
BSF PORTB,2 ;Set bit2 of PORTB

CH1 BTFSC PORTB,3 ;Is bit3 of PORTB clear?
GOTO CH4 ;No
MOVLW B'00000110' ;Yes output 1
MOVWF PORTC

CH4 BTFSC PORTB,4 ;Is bit4 of PORTB clear?
GOTO CH7 ;No
MOVLW B'00000110' ;Yes output 4
MOVWF PORTC

CH7 BTFSC PORTB,5 ;Is bit5 of portB clear?
GOTO CH11 ;No
MOVLW B'00000111' ;Yes output 7
MOVWF PORTC

CH11 BTFSC PORTB,6 ;Is bit 6 of portB clear?
GOTO C2 ;No
MOVLW B'001110110' ;Yes output 1
MOVWF PORTC

C2 BSF PORTB,0 ;Set bit0 of PORTB
BCF PORTB,1 ;Clear bit1 of PORTB
BSF PORTB,2 ;Set bit2 of PORTB

CH2 BTFSC PORTB,3 ;Is bit3 of PORTB clear?
GOTO CH5 ;No
MOVLW B'01011011' ;Yes, output 2
MOVWF PORTC

CH5 BTFSC PORTB,4 ;Is bit4 of PORTB clear?
GOTO CH8 ;No
MOVLW B'01101101' ;Yes, output 5
MOVWF PORTC

CH8 BTFSC PORTB,5 ;Is bit5 of PORTB clear?
GOTO CH10 ;No
MOVLW B'01111111' ;Yes, output 8
MOVWF PORTC

CH10 BTFSC PORTB,6 ;Is bit6 of PORTB clear?
GOTO C3 ;No
MOVLW B'00111111' ;Yes, output 0
MOVWF PORTC

C3 BSF PORTB,0 ;Set bit0
BSF PORTB,1 ;Clear bit1 of PORTB
BCF PORTB,2 ;Set bit2 of PORTB

CH3 BTFSC PORTB,3 ;Is bit3 of PORTB clear?
GOTO CH6 ;No
MOVLW B'01001111' ;Yes, output 3
MOVWF PORTC

CH6 BTFSC PORTB,4 ;Is bit4 of PORTB clear?
GOTO CH9 ;No
MOVLW B'01111101' ;Yes, output 6
MOVWF PORTC

CH9 BTFSC PORTB,5 ;Is bit5 of PORTB clear?
GOTO CH12 ;No
MOVLW B'01101111' ;Yes, output 9
MOVWF PORTC

CH12 BTFSC PORTB,6 ;Is bit6 of PORTB clear?
GOTO C1 ;No
MOVLW B'01001001' ;Yes, output 0
MOVWF PORTC

END



Any help would be very much appreciated, thanks.

NavMicroSystems
- 5th May 2005, 23:29
douglasjam,

this is a PICBASIC Forum, not an Assembler Forum !