pic compiler micro c doubt
Discussion in "PIC Microcontroller Discussion" started by laki Dec 14, 2007.
Fri Dec 14 2007, 12:38 pm
i'm using micro c compiler for pic16f877a. i don't know how to get input from a port i.e my statement in C is
variable=PORTB;
but it won't work.. what do i do??
variable=PORTB;
but it won't work.. what do i do??
Fri Dec 14 2007, 12:49 pm
well that code is correct for reading value from PORTB.
make sure you have made it as input port..
also may i see your program..to know better what you are doing..?
make sure you have made it as input port..
also may i see your program..to know better what you are doing..?
Fri Dec 14 2007, 12:59 pm
here's the prog. i'm trying to read a value from port B and control a motor depending on the value. PORTA is connected to an l293d.
void forward(); void right(); void left(); void stopped(); void forward(void) { PORTA=0B11010100; } void stopped(void) { PORTA=0x00; } void right(void) { PORTA=0b10010000; } void left(void) { PORTA=0b01000100; } void main() { TRISA=0X00; TRISB=0B11111111; CMCON=0x07; while(1) { getval=PORTB; Delay_500us(); if(getval==0) { stopped(); } else if(getval==1) { forward(); } else if(getval==3) { right(); } else { left(); } } }
[ Edited Fri Dec 14 2007, 01:10 pm ]
Fri Dec 14 2007, 01:11 pm
can you tell me the name of compiler you are using? are you sure you are not getting any compiler errors?
Fri Dec 14 2007, 01:24 pm
what is the error?
make sure you include the header file relevant to your controller.
tell me is it the same compiler?
http://www.programmersheaven.com/download/2670/download.aspx
or
http://www.ccsinfo.com/
make sure you include the header file relevant to your controller.
tell me is it the same compiler?
http://www.programmersheaven.com/download/2670/download.aspx
or
http://www.ccsinfo.com/
[ Edited Fri Dec 14 2007, 01:38 pm ]
Fri Dec 14 2007, 02:16 pm
because your port is 8-bit.. means data will be of 1 byte only.. so why to waste 2 bytes using INT?
always try to keep your variables as unsigned char or char..when you are dealing with 8-bit data... this is a kind of optimization tip. RAM usage will be less in this case..
always try to keep your variables as unsigned char or char..when you are dealing with 8-bit data... this is a kind of optimization tip. RAM usage will be less in this case..
laki like this.
Powered by e107 Forum System