View previous topic :: View next topic |
Author |
Message |
prafulla.prolific
Joined: 05 Jun 2013 Posts: 10 Location: Mumbai
|
Help For reading Port Data |
Posted: Thu Jun 06, 2013 1:06 am |
|
|
I am using PIC 16F873A controller 8 keys attached to controller. On PORT_A (6 keys) from Pin A0-A5, and ON Port B (2 keys) Pin B4, & B5. I am writing Port_A make with pullup make Port_A High and read PORT_A data if Port_A data changes means changes in key status they next process of debounce carried out.
I had write code as following as shown in example but shows error as
: expecting LVALUE such as variable name or * expression
Code: |
unsigned int8 key2_data(void);
unsigned int8 data1(void);
unsigned int8 data2(void);
unsigned int8 key_data(void);
void chk_status(void)
{
data1=input_B();
data2=input_A();
key2_data = ( data1 & 0x30);
key2_data = key2_data <<2;
key_data = (( data2 & 0x3F)|( key2_data & 0xa0));
} |
i had also change input_B as PORT_B,please guide how to read port data. _________________ I m Working as PIC Programmer Fresher |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Jun 06, 2013 7:11 am |
|
|
Nothing wrong with the input. Problem is the data definitions....
You are defining key2_data, as a _function_ returning an int8, not as a variable.
Same applies to all the other variables....
With some further tidying (for instance, you have already and'ed the incoming port value with 0x30, before the rotation, so why and it again with 0xA0 - just wasted time.
Also as a comment, use local variables, and return the value from the function.
Code: |
int8 chk_status(void)
{
int8 temp;
temp=(input_B()<<2) & 0xA0);
temp=(input_A() & 0x3F) | temp;
return temp;
}
|
Note the variable declaration, and how the function returns the result.
Do some basic reading on how to declare variables in C.
Best Wishes |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Jun 06, 2013 7:24 am |
|
|
you are treating function templates as if they are VARS
read your basic C manual
this is wrong syntax you attempt to compile.
not a CCS problrm
ohh whoops - MR. T was setting this right as i was typing Slowly |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Jun 06, 2013 8:34 am |
|
|
Stereo posting is very common. Usually I'm the one typing slower...
Best Wishes |
|
|
prafulla.prolific
Joined: 05 Jun 2013 Posts: 10 Location: Mumbai
|
|
Posted: Fri Jun 07, 2013 11:56 pm |
|
|
Thanks Ttelmah, its my mistake i will try.
Ttelmah wrote: | Nothing wrong with the input. Problem is the data definitions....
You are defining key2_data, as a _function_ returning an int8, not as a variable.
Same applies to all the other variables....
With some further tidying (for instance, you have already and'ed the incoming port value with 0x30, before the rotation, so why and it again with 0xA0 - just wasted time.
Also as a comment, use local variables, and return the value from the function.
Code: |
int8 chk_status(void)
{
int8 temp;
temp=(input_B()<<2) & 0xA0);
temp=(input_A() & 0x3F) | temp;
return temp;
}
|
Note the variable declaration, and how the function returns the result.
Do some basic reading on how to declare variables in C.
Best Wishes |
_________________ I m Working as PIC Programmer Fresher |
|
|
|