Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] WTA How to store value in general purpose register (16F628a)

Status
Not open for further replies.

alpha91

Full Member level 3
Joined
Sep 23, 2011
Messages
168
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,298
Activity points
2,625
Hi all,

I am learning C language for PIC microcontroller and I am trying to write some data in general purpose register ( using 16F628a).

Example in assembly language:
TEMP1 EQU 10; declare address 10h as TEMP1
MOVLW b00001111;
MOVWF TEMP1;

May I know how can to declare address and store it like this code?
 

In 'C' it's best to leave the compiler to allocate the address for 'TEMP1' but the instruction is just "TEMP1 = 0x0F;" or "TEMP1 = 0b0001111;" if the compile supports it.

Brian.
 
In 'C' it's best to leave the compiler to allocate the address for 'TEMP1' but the instruction is just "TEMP1 = 0x0F;" or "TEMP1 = 0b0001111;" if the compile supports it.

Brian.

Hi, Brian, thank you very much.
it works, i am using MikroC compiler.
just that i need to declare the name like " unsigned char TEMP1"
:thumbsup:
 

Well done!

Be careful with the declarations. The way the varibles are stored is the same if you use 'unsigned' or not but the way it is interpreted by some operations is different. Most compilers default to a 'char' as signed which means bit 7 is used to indicate positive (0) or negative (1). That limits the range of numbers it can hold because only bit 6 through to bit 0 are left to hold the data. When you add 'unsigned' to the declaration it tells the compiler to use all the bits to hold data as it would in assembly language but you lose the ability to store negative values.

Brian.
 
Well done!

Be careful with the declarations. The way the varibles are stored is the same if you use 'unsigned' or not but the way it is interpreted by some operations is different. Most compilers default to a 'char' as signed which means bit 7 is used to indicate positive (0) or negative (1). That limits the range of numbers it can hold because only bit 6 through to bit 0 are left to hold the data. When you add 'unsigned' to the declaration it tells the compiler to use all the bits to hold data as it would in assembly language but you lose the ability to store negative values.

Brian.

I see. I never know that because i always use unsigned char.
Thank you very much for your information. :razz:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top