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.

[SOLVED] help pic16f877a programming INPUT and OUTPUT

Status
Not open for further replies.

luigi_moran23

Newbie level 5
Newbie level 5
Joined
Mar 4, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,365
I am using MPLAB and I can already output an LED, the problem now that I faced is that I don't know how to program an input to microcontroller as well as its schematic? If there was someone out there that has knowledge of the basic of input output port please share me your codes as well as your schematic.

Thank You Very Much

Luigi Moran
 

Connect a one end of switch to RA0 and other end to =5V through 10k resistor. Also connect pin RA0 to ground. Connect a led to pin RB0.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
TRISA = 0b00000001;
PORTA = 0x00;
 
while(1) {
 
if(PORTAbits.RA0 == 1) {
 
//call delay 30 ms here
if(PORTAbits.RA0 ==1) {
 
PORTBbits.RB0 = ~PORTBbits.RB0
 
}
 
}
 
}

 

hey I just solved it. I am sorry that I forgot to mention that I need to be assembly language. But anyway thanks for your help sir.:) this is my code in assembly:
#include p16F877.inc
__config _XT_OSC & _WDT_OFF & _LVP_OFF & _PWRTE_ON

ORG 0

RESET
nop
goto START

ORG 4

START
bsf STATUS,RP0
movlw b'11111111' ; Set PORTA direction all input
movwf TRISB
movlw b'11111110' ; Set PORTB direction all output
movwf TRISC
bcf STATUS,RP0

MAIN
btfss PORTB, 0;
goto ledoff ;skip if RBO is on(1)
ledon
bsf PORTC, 0 ;set bit RC0 to on
goto MAIN ;back to MAIN
ledoff
bcf PORTC, 0 ;clear bit RC0 to off
goto MAIN ;back to MAIN
end
 

Not really but yes. Actually the one really I want something like this: If a push button was pressed, an LED will LIGHT up. And through the code that I post, I succesfully done it too. By the way, I want to ask sir if You know how to program pic16f877a in assembly language the Serial programming. The scenarion should be like this: If a computer sends a digit "1" via hyperterminal, RB0 will light LED and if a push button was attached to RB1, the microcontroller will send a number "2" to the computer which will should be seen in hyperterminal. Thanks for the help sir.:)
 

I haven't done serial communication programming in assembly. You need to use an interrupt routine for receiving data. Enable GIE and Initialize registers related to serial communication. Make a routine for Tx and Rx using interrupts. I think you use TxSTAbits.TRMT for transmitting data. See C code at saeedsplutions.blogspot.com for UART and inplement it in assembly or post the C code you get there and I will try to write the assembly code.
 

Going from turning a LED on and off to then writing a serial routine is a bit ambitious, try something simpler first, like flashing LEDs in a pattern or later writing to a LCD etc.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top