PDA

View Full Version : word size (8 bits???)



boldozoi
- 21st July 2004, 07:27
I declare a variable as word'

quartz var word
quartz=300
and when simulating in MPLAB I get an 8 bit number
quartz=44


This happens for all variables declared as words.
I use this code for a PIC16c745.
Can anyone give me a piece of advise?

10X.

Dwayne
- 21st July 2004, 22:40
quartz var word
quartz=300
and when simulating in MPLAB I get an 8 bit number
quartz=44

Check the other half of your word...

What you have is 300= 256 + 44.

0000 0001 0010 1100
$01 $2C
256 44
300


You are seeing the $2C, and missing the MSB of your Word, which will have your 256.

Since we do not have any Code to look at, it is harder to see what is going on... Can give us some exact code that is causing your problem??? Are you assigning a Variable as a Byte instead of a word? Are you trying to output to a LCD??? A LCD is 8 bytes.. that means you had better not forget to add the MSB to your answer!...and transfer that to the LCD. (I am assuming you are writing your own LCD stuff).


Dwayne

boldozoi
- 22nd July 2004, 07:35
Thank you for the replay.
I try to control with this code a programmable wave generator. It has a serial interface. The word lengths it accepts is 16.
The problem is that in MPlab when simulation the code is that all my word variable are reprezented as 8 bits. For clarity I'll post the poart of the code related to this wave generator:

' code for driving a Prgrammable Wave generator
'It receives from pic words of 16 bits for configuration

powrez var word
pow var word
i2 var byte
date var word
tmp1 var word
tmp2 var word
len var byte
biti var bit[16]
pinul var byte
f var word
f1 var word
Frec var word
quartz var Word
s9833 var bit


TRISC = %00000000 ;all output
TRISA = %00111111 ;all input
Define OSC 24
start: ADCON1 = 7
high PORTC.6
high PORTC.7

quartz=300
Frec=quartz/2
s9833=0
high PORTC.1
gosub setup9833
s9833=1

'function that computes the 2^pow and store the result in powrez
power:
powrez=1
powrez = powrez << pow
return

' this function transforms a number (ie 5 ) into a serial array (00001001- for len=8bits, bit(0)=0, ....biti(4)=1, biti(5)=0...biti(7=1)) and then sends this array on the PORTC.2, simmulation the clock on the PORTC.0

sendit:
pow=len-1
gosub power
tmp1=powrez
for i2 = 1 to len-1
pow=len-i2-1
gosub power
tmp2=powrez
if ((date//tmp1>date//tmp2)) then
biti[i2]=1
else
biti[i2]=0
endif
tmp1=tmp2
next i2
for i2=0 to len-1
pause 100
high PORTC.0
pause 100
if (biti[i2]=0) then
if pinul = 1 then low PORTC.1
if pinul = 2 then low PORTC.2
else
if pinul = 1 then high PORTC.1
if pinul = 2 then high PORTC.2
endif
pause 100
low PORTC.0
pause 100
next i2
return

' this function setup the wave generator (active low)
'the frequency of the signal is transmitted as two 16 bits words (f,f1)
'the other data are control words

setup9833:
High PORTC.0
'pause 5
low PORTC.6
if s9833<>0 then
date=%0010000000000000
else
date=%0010000100000000 ' chip reset
endif
len=16
pinul=2
gosub sendit
pow=28
gosub power
f=powrez/quartz
f=f*Frec
pow=14
gosub power
f1=f//Frec
pow=28
gosub power
f=f//Frec
f=f-f1
pow=14
gosub power
f1=f1+powrez
f=f/powrez
f=f+powrez
date=f1
gosub sendit
date=f
gosub sendit
if s9833=1 then
date=%0000000000000000
gosub sendit
date=%1100000000000000
gosub sendit
endif
high PORTC.0
pause 100
high PORTC.6
return

In MPlab the date variable(binary) 00000000, quartz 00101100 and the same for all my word declared variables
I hope my problem is clearer now.
Thank you again Dwayne for the replay.

Dwayne
- 26th July 2004, 19:50
Hello Bold,

Bold>>quartz=300
Frec=quartz/2<<


This is kinda redundant....Why not assign Frec=150?

If you need to, use the DIV32 command instead of the "/".

Dwayne

boldozoi
- 27th July 2004, 06:59
Thank you for the reply. I went on and found that the compiler did use 16 bits for every word. However MPlab showd in the simulations only 8 bits.
As i'm about to finish the project, this doesn't matter anymore.
It's still strange why MPlab shows only 8 bits but at least I found that the compiler uses the 16 bits.
Thank you again for replaying.