CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to print rom value on 16F628A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

How to print rom value on 16F628A
PostPosted: Sun Jan 24, 2016 10:05 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Jan 24, 2016 11:15 am     Reply with quote

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.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sun Jan 24, 2016 11:32 am     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 24, 2016 1:48 pm     Reply with quote

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:
Quote:

08
08

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);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Jan 24, 2016 2:41 pm     Reply with quote

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.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Jan 26, 2016 11:39 am     Reply with quote

Thanks. It answers a lot of my questions.
_________________
A person who never made a mistake never tried anything new.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group