word size (8 bits???)


Closed Thread
Results 1 to 5 of 5
  1. #1
    boldozoi's Avatar
    boldozoi Guest

    Default word size (8 bits???)

    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.

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    boldozoi's Avatar
    boldozoi Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  5. #5
    boldozoi's Avatar
    boldozoi Guest


    Did you find this post helpful? Yes | No

    Talking

    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.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  3. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23:19
  4. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts