PDA

View Full Version : constants



cmolson
- 1st December 2005, 06:10
Hello, I am pretty new to picbasic and have some questions which should be pretty straight forward.

I am writing a program to send data serially out using the debug command and have confirmed to be able to use 9600bps at 3.579mhz. I need to send the data in inverted form so this is the code I use to declare and invert a variable:

A4 var byte
A4=~$A4 REV 8

Is there a way to do this using constants? I have a lot of bytes I need to do this with and I don't want to manually invert them by hand because they lose their meaning to people reading the code that way.


I would like to do this for example:

A4 CON ~$A4 REV 8

The ~ inverts the bits, and the REV8 reverses it. However this does not compile. It only works when I declare it as a variable. Maybe i could use some kind of table and lookup method? Thanks!

Kamikaze47
- 1st December 2005, 06:22
Why not convert them manually and comment each line so u know whats going on... e.g.:

A4 CON $DA 'Inverted and Reversed $A4

cmolson
- 1st December 2005, 06:25
wow, good idea thanks!. As all these variables will quickly eat up my ram space. I jsut wish it was easier for me to update the code later on without inversing stuff. Thansk for the quick reply!

cmolson
- 1st December 2005, 06:26
One more question though, is it possible to make an array constant? I would like to make one with 9 byts in it. I'm not sure how to go about that. The bytes are hex.

Kamikaze47
- 1st December 2005, 06:33
No I dont think you can make an array constant. If you want an array you will have to use a variable like this:

label VAR BYTE[length]

mister_e
- 1st December 2005, 13:33
As all these variables will quickly eat up my ram space


Why not using the internal eeprom instead?



ArrayIndex var byte
ArrayData var byte

' PreLoad EEPROM at programming time
' ===================================
'
data @0,$10,$20,$30,$40,$50
'
'
' Read data from EEPROM
' =====================
'
Read ArrayIndex,ArrayData


Usually that's what i do instead of using Array... well if the PIC have EEPROM and/or free EEPROM storage.

Good luck!