View previous topic :: View next topic |
Author |
Message |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
Matrix with BIT and location memory |
Posted: Sun May 27, 2018 10:55 am |
|
|
Hy.
I have code that is not working properly.
on main.c
Code: | while(TRUE)
{
if (input(K1)==1){
BIT_LED();
}
} |
on 12f509.h
Code: | static unsigned int16 DIV_PR;
#locate DIV_PR = 0x30 //and 0x31
static unsigned int8 BUTTON;
#locate BUTTON = 0x32
static unsigned int8 TIME_SEL;
#locate TIME_SEL = 0x33
static int1 DATA_LED[16];
#bit DATA_LED = 0x34.0
//#bit DATA_LED = 0x35.0
static unsigned int8 i;
#locate i = 0x36
static unsigned int8 DELAY;
#locate DELAY = 0x37
|
and lst file
Code: |
static unsigned int16 DIV_PR; //
004A: BSF 04.5
004B: CLRF 10
004C: CLRF 11
.................... #locate DIV_PR = 0x30
.................... static unsigned int8 BUTTON;
004D: CLRF 12
.................... #locate BUTTON = 0x32
.................... static unsigned int8 TIME_SEL;
004E: CLRF 13
.................... #locate TIME_SEL = 0x33
.................... static int1 DATA_LED[16];
004F: BSF 04.7
0050: CLRF 00
0051: CLRF 01
.................... #bit DATA_LED = 0x34.0
.................... //#bit DATA_LED = 0x35.0
.................... static unsigned int8 i;
0052: BCF 04.7
0053: CLRF 16
.................... #locate i = 0x36
.................... static unsigned int8 DELAY;
0054: CLRF 17
.................... #locate DELAY = 0x37 |
and an on another c file
Code: | #define ACTIV_LED delay_us(1),(output_bit(OC,1), delay_us(1), output_bit(OC,0))
void BIT_LED(void)
{
i=0;
while (i<18){
output_bit(OD, DATA_LED[i]);
ACTIV_LED;
i++;
}
} |
The problem is: when I run the program returning different value on DATA_LED[9] is like "1", and all other is "0" as is defined on beginning.
Have someone an idea of what's happening? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Sun May 27, 2018 11:28 am |
|
|
I can't actually see 'why' you are #locating most of the things?. Just let them go where they want to go. #locate should only be used to do things like map a variable to one of the SFR's. Moving stuff around otherwise is just asking for problems....
#bit locates a single bit variable at the location defined. It does not say that it can be used to locate an existing variable, To locate the array, use:
Code: |
static int1 DATA_LED[16];
#byte DATA_LED = 0x34
|
#byte as it's secondary function can locate any already declared variable to a location.
Whether that will work I don't know, but it is more correct than trying to use a #bit definition on the array. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Sun May 27, 2018 1:32 pm |
|
|
yes Ttelmah you are right.
#word is solution.
Code: | static int1 DATA_LED[16];
#word DATA_LED = 0x34 |
Now is working.
Thank you. |
|
|
|