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.

switch pressing Usart identification problem

Status
Not open for further replies.

td micro

Member level 5
Joined
Jun 26, 2012
Messages
86
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,929
hi..
i write one program to identify the switch pressed, which is connected to pic 18f port B0. when switch is pressed,it is connected to ground. but i m not getting the proper output.. USART communication is ok... here is my code..

void main(void)
{
int x;
TRISB=1;
LATB=1;
INTCON2bits.RBPU=0; //enable pull up
WPUBbits.WPUB0=1;
ANSELH=0x00;
EnableUART();

printf("plz press key");


while(1)
{
x=LATBbits.LATB0 ;
if (x==0)
printf("key pressed");
}
}


plz plz help me to solve this..
 

x=LATBbits.LATB0 ;
This reads the output latch, which you already set high.

Try x=PORTBbits.RB0 ;

Not sure if I got the syntax right for your compiler, but usually you will want to read (input) from PORT and write (output) to LAT register
 

HI

Please check with your circuit using multimeter, while pressing the button the voltage gets dropped or not, i not sure about that syntax of your compiler, but u have to scan the input level of pin by using the trisb register....
 

i got the output key pressed....thanks..thank you very much for your help...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top