Try this
for n = 15 to 0 step -1
Ioannis
I just realised what I did...
dout = dout << 1
lcdout $fe,14,bin dout.15
I was displaying the dout bit after it had shifted... Stupid me.. I swapped those 2 lines, and I know I am giving the right string of bits to the array...
I'm trying to display the array to see if all those bits went in.. Something is not right tho.
This last bit where I try to display the cmd array just gives me garbage characters.Code:n VAR BYTE nn VAR BYTE cmd VAR BYTE[15] ... lcdout $fe,$C0," " for n = 15 to 0 step -1 CMD.0[n] = dout.15 lcdout $fe,14,bin dout.15 dout = dout << 1 next n lcdout $fe,$d4," " for nn = 0 to 15 lcdout $fe,$14,cmd.0[nn] next nn
Last edited by davewanna; - 10th June 2008 at 12:03.
I have just read a very in depth post by Melanie about bits in bytes, and arrays etc...
I think I understood most of it.. and have changed my code to....
However it still doesn't seem to have solved my problem. I am still getting the wierd character in the bottom lcdout array..Code:n VAR BYTE nn VAR BYTE cmd VAR BYTE[16] ... lcdout $fe,$C0," " for n = 15 to 0 step -1 CMD[n] = dout.15 lcdout $fe,14,bin dout.15 dout = dout << 1 next n lcdout $fe,$d4," " for nn = 0 to 15 lcdout $fe,$14,cmd(nn) next nn
Latest code is...
This displays the binary that I want to feed to the RF12 on the LCD... However it still has not changed the osc freq of the RF12. Despite being in a loop giving the command over and over...Code:Start: lcdout $fe,$80,"RFM12B OSC test" lcdout $fe,$94,"1MHz to 10Mhz" pause 200 dout = $C0F7 gosub Writecmd goto Start WriteCMD: for n = 15 to 0 step -1 CMD[n] = dout.15 dout = dout << 1 next n lcdout $fe,$c0," " SCK = 0 nSEL = 0 for nn = 15 to 0 step -1 if cmd[nn] = 1 then gosub write1 else gosub write0 endif lcdout $fe,$14,bin cmd[nn] next nn sck = 0 nSel = 1 return Write0: SDI = 0 : SCK = 0 : pauseus 16 : SCK = 1 : return Write1: SDI = 1 : SCK = 0 : pauseus 16 : SCK = 1 : return
Last edited by davewanna; - 10th June 2008 at 14:04.
Ok so it is working... As far as I have set all the initialize registers as per the datasheet example with the exception of the 10MHz clock line, and a 4.5V low battery detect...
I can now see the clock line change to 10MHz
Working code is below...
Code:define osc 4 ' Define LCD registers and bits DEFINE LCD_DREG PORTD 'LCD addressing DEFINE LCD_DBIT 4 'L1 = $80 DEFINE LCD_RSREG PORTD 'L2 = $C0 DEFINE LCD_RSBIT 1 'L3 = $94 DEFINE LCD_EREG PORTD 'L4 = $D4 DEFINE LCD_EBIT 3 lcdrw var portd.2 nSEL var portb.4 SDI var portb.5 SCK var portb.6 SDO var portb.7 dout var word n VAR BYTE nn VAR byte cmd var bit[16] TRISB = %00000100 low lcdrw nSEL = 1 SDI = 1 SCK = 0 pause 500 lcdout $fe,1 Start: lcdout $fe,$80,"RFM12B Initialize" pause 500 gosub Init goto start 'Subroutines WriteCMD: for n = 15 to 0 step -1 CMD[n] = dout.15 dout = dout << 1 next n SCK = 0 nSEL = 0 for nn = 15 to 0 step -1 if cmd[nn] = 1 then gosub write1 else gosub write0 endif next nn sck = 0 nSel = 1 pause 500 return Write0: SDI = 0 : SCK = 0 : pauseus 16 : SCK = 1 : pauseus 1 : return Write1: SDI = 1 : SCK = 0 : pauseus 16 : SCK = 1 : pauseus 1 : return Init: dout = $80D8 'enable register, 433MHz, 12.5pf gosub Writecmd dout = $8208 'Turn on crystal, !PA gosub Writecmd dout = $A640 gosub Writecmd dout = $C647 gosub Writecmd dout = $94C0 'VDI, FAST, 134kHz gosub Writecmd dout = $C2AC gosub Writecmd dout = $CA80 gosub Writecmd dout = $CA83 'FIFO8, SYNC gosub Writecmd dout = $C49B gosub Writecmd dout = $9850 '!mp, 9810=30kHz, Max Out gosub Writecmd dout = $E000 'Not Used gosub Writecmd dout = $C80E 'Not Used gosub Writecmd dout = $C0F7 '10MHZ, 4.5V gosub Writecmd Return
This has been very painful for me - having not touched RF before, so I'm hopeing that someone else gets some use out of my hair-pulling...
There is much more to do, I haven't even got round to sending data yet, and I haven't worked out how you are meant to run the pic on the 1MHz clock, then set it to 10Mhz, and have it all work fine. At the moment I have it running on an external 4Mhz crystal.
When I get a good working TX and RX bit of code I will start a new post with as much info as I can work out...
Thanks again to all the people that helped me get this far!
Cheers
Dave
Note to yourself, even though in this case it doesn't matter (because the default OSC is 4), the DEFINE's MUST be in CAPS, either the DEFINE itself, or the parameters, I don't remember which. In my case, I always just put both in caps. Don't have to figure out which one then.
This should do exactly the same thing, but uses the shiftout command. Assuming your original program worked as you wanted it to work....Code:DEFINE OSC 4 DEFINE LCD_DREG PORTD 'LCD addressing DEFINE LCD_DBIT 4 'L1 = $80 DEFINE LCD_RSREG PORTD 'L2 = $C0 DEFINE LCD_RSBIT 1 'L3 = $94 DEFINE LCD_EREG PORTD 'L4 = $D4 DEFINE LCD_EBIT 3 DEFINE SHIFTPAUSE_US 16 include "modedefs.bas" lcdrw var portd.2:nsel var portb.4:sdi var portb.5:sck var portb.6:sdo var portb.7 dout var word:trisb=4:lcdrw=0:nsel=1:sdi=1:sck=0:pause 500:lcdout $fe,1 Start: lcdout $fe,$80,"RFM12B Initialize":pause 500:gosub Init:goto start WriteCMD: nsel = 0 : shiftout sdi , sck , 5 , dout\16 : nsel = 1 : return Init: for temp = 0 to 12 lookup temp , [ $80D8 , $8208 , $A640 , $C647 , $94C0 , $C2AC , $CA80 , $CA83 , $C49B , $9850 , $E000 , $C80E , $C0F7 ] , dout gosub writecmd next temp Return![]()
Here come the colon again!
Well, Dave, actually you are running the Oscillator of the PIC at 4MHz, but the core is running at 1MHz (/4).
If you want the pic running at 10MHz, then you should capitalize the define on top of the program as Skimask stated like this:
DEFINE OSC 10
After that, compiler will take care of the rest timing.
Ioannis
Bookmarks