Is there a more elegant way to set high & low bytes?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Blue Bill
Posts: 10
Joined: Thu Sep 27, 2012 3:37 pm
Location: Toronto

Is there a more elegant way to set high & low bytes?

Post by Blue Bill » Wed May 29, 2013 1:54 pm

Code: Select all

Clock = 8		   
#option SetBaud1 = 38400
#option MIPx10 = _clock * 2500000 
Const Baud1 As Word = (MIPx10 / SetBaud1 - 5) / 10                                
TBLPTRH = Baud1 >> 8 And $FF
TBLPTRL = Baud1 And $FF
The ".Byte0" and ".Bytes(0)" don't compile, are they part of a module?
Blue Bill (aka BlueRoomElectronics)

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Wed May 29, 2013 4:45 pm

The variable modifiers (.byte0, .bytes, .bits, etc) only work with variables, not CONSTs

Another way might be

Code: Select all

TBLPTRH = byte(Baudl >> 8)
TBLPTRL = byte(Baudl)
As far as that being "more elegant", that's your call. It produces the same code.

Post Reply