View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
How to print rom value on 16F628A |
Posted: Sun Jan 24, 2016 10:05 am |
|
|
Is there any (direct or indirect) to print the value of ri?
Code: |
#include <16f628A.h>
#include <stdint.h>
#fuses INTRC_IO, NOWDT, MCLR, NOPROTECT, BROWNOUT
#device *=16
#device PASS_STRINGS=IN_RAM
#use delay(clock=4M)
#USE RS232 (UART1, BAUD=9600, ERRORS)
rom int ri = 8;
void main(void)
{
setup_oscillator(OSC_4MHZ);
delay_ms(1000);
while(TRUE)
{
output_toggle(PIN_B5);
printf("Hello, %d\n",ri);
delay_ms(1000);
}
} |
There is no build error, instead code crashes on printf line. I see "Hello" and then processor hangs. _________________ A person who never made a mistake never tried anything new.
Last edited by rikotech8 on Sun Jan 24, 2016 11:30 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19367
|
|
Posted: Sun Jan 24, 2016 11:15 am |
|
|
Er.
Where is p_ri declared?.
You have two different declarations of 'ri'. You do understand that in C if you have a local variable and a global variable of the same name, the local will be used?.
What you have posted, won't compile. It'll complain immediately that p_ri is undefined. |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Sun Jan 24, 2016 11:32 am |
|
|
Yes, it was a mistyping. I edited my original post. Everything else is same. _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2016 1:48 pm |
|
|
I don't think 'rom' will work with the 16F628A because it doesn't support
read/write of it's own flash memory under program control.
For example, the program below produces no output in MPLAB (vs. 8.92)
simulator with the 16F628A. But with 16F877 and 16F1847, it produces this:
Test program:
Code: | #include <16F628A.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
rom int ri = 8;
//=====================================
void main(void)
{
int8 temp;
printf("%x \r", ri);
temp = ri;
printf("%x \r", temp);
while(TRUE);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19367
|
|
Posted: Sun Jan 24, 2016 2:41 pm |
|
|
That makes sense.
And obvious comment, if you just want to store values in the ROM and print them, use const. For this the compiler will create a program able to return the required values, which allows this to work even on chips without ROM access. |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Tue Jan 26, 2016 11:39 am |
|
|
Thanks. It answers a lot of my questions. _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
|