Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Trouble with manual controlling LED though PIC16F877A

Status
Not open for further replies.

tkb5416

Newbie level 4
Joined
Nov 22, 2009
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
Hi,
I have faced some problems with lighting LEDs thought PIC16F877A. When there is input through PORTA, the LEDs in PORTD will light up. But, when the input is disconnect, the LEDs in PORTD are on and sometimes blinking unstably.

I have connected VPP,VDD to +5 and VSS to GND. I used 20 Mhz crystal with two capacitors that are connected to GND.

I do not know what has gone wrong with this experiment.

I really need your help. Thank you.

****************************************************************


LIST P=16F877A
#include <P16F877A.INC>

; Configuration
__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON
STATUS equ 0X03
ADCON1 equ 0X9F
PORTA equ 0X05
PORTD equ 0X08


;main routine
ORG 00
GOTO MAIN

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MAIN
BCF STATUS, RP1
BSF STATUS, RP0 ; select Bank1
MOVLW B'00000110'
MOVWF ADCON1 ; assign Digital Port Configuration Pins
MOVLW B'00001111'
MOVWF TRISA ; set pin0-3 of PortA as input
CLRF TRISD ; set all pins of PortD as output

BCF STATUS, RP1
BCF STATUS, RP0 ;select Bank0
CLRF PORTA
CLRF PORTD
GOTO LOOP

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LOOP


; LED_CONTROL
BTFSC PORTA, 0
CALL LED_PATTERN0
BTFSC PORTA, 1
CALL LED_PATTERN1
BTFSC PORTA, 2
CALL LED_PATTERN2
BTFSC PORTA, 3
CALL LED_PATTERN3
GOTO LOOP


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


LED_PATTERN0
MOVLW B'00001001'
MOVWF PORTD
BTFSC PORTA, 0
GOTO LED_PATTERN0
CLRF PORTD
GOTO LOOP

LED_PATTERN1
MOVLW B'00000110'
MOVWF PORTD
BTFSC PORTA, 1
GOTO LED_PATTERN1
CLRF PORTD
GOTO LOOP

LED_PATTERN2
MOVLW B'00000101'
MOVWF PORTD
BTFSC PORTA, 2
GOTO LED_PATTERN2
CLRF PORTD
GOTO LOOP

LED_PATTERN3
MOVLW B'00001010'
MOVWF PORTD
BTFSC PORTA, 3
GOTO LED_PATTERN3
CLRF PORTD
GOTO LOOP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

END


****************************************************************
 

Hi,


While the code you show looks ok, its not possible to check it fully.

You need to show what the controlling input is - switches ? , if so you really need to debounce them with a 50ms delay.

How are the switches and leds wired, pulled up or down, leds sink or source ?

No reference in your code to the routines Forward, Left etc ?
 

Hi Wp100,
I have corrected the mistake I made. I replaced the LEFT,RIGHT,... to LED_PATTERN.Thanks for reminding me.

I am using Pushbutton switches to connect the inputs on PORTA . When the switch is connected, it connects directly to +5Vcc. I did not place any components else except Pushbutton switches at inputs on PORTA.

The LEDs on PORTD are connected with resistor 330 Ohm and to Ground.

Thank you.
 

Hi,

Not sure how you have wired things but this is the way to go.

You can use either All Pull up or All Pull down for the switches , but you must match that with your code - btfss or btfsc when testing PortA

Any switch resistors 4.7k to 10k will be fine - you can mix.
 

Hi WP100,
I have used Pull down for the switches with 10K Ohm resistors to ground just like in the schematic you have provided. It works!

The LEDs are on when connected and off when disconnected. The problem I faced previously was solved.

Thank you very much :D
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top