Welcome! Log In Create A New Profile

Advanced

Bypic code

Posted by thomas.smith57 
Bypic code
March 04, 2013 11:27PM
I am just changing from BV-basic to Bypic basic having upgraded my BV513.. In the BV basic guide there is a short prog. to flash the on-board
LED.
Could someone show me how that would be done in Bypic

Thanks
M Smith
Re: Bypic code
March 07, 2013 09:48AM
** Update Apr 2013 - rookie is now avaiable to make tasks like this much easier **
hello,
here is the code to flash the on board LED.
// Simple LED flasher for BV513
//
// This selects the action type
constant CLR 4
constant SET 8
constant INV 12
// The LED is conneted to RC15
constant LED 1 << 15     // this is the port
constant LEDTRIS  0xBF886080 // this is TRISC
constant LEDLAT  0xBF8860A0 // this is LATC

// *****************************************************************************
// Flash on board, BV513 LED 10 times
// *****************************************************************************
function flash()
dim j
    // first set up the port that the LED is on
    poke(LEDTRIS+CLR,LED) // set to output
    // Now flash the led
    for j = 1 to 10
        poke(LEDLAT+INV,LED)
        wait(100)
    next
endf

It is slightly more involved than the old BV_Basic as he ports need setting first by using direct register access. This does however give much more flexibility as ANY hardware that is on the IC (not just ports) can be supported simply by selecting and manipulating the correct registers.



Edited 1 time(s). Last edit at 04/28/2013 09:06AM by jimeer.
Re: Bypic code
March 07, 2013 11:34PM
Thanks for your help, things are jelling, but slowly

Malcolm
SD card files
March 13, 2013 11:40PM
I have been using a pre-ByPic SD card in my BV513. This contains 37files after I successfully deleted some using the ByPic command. These show up with the DIR command. I have now got a new SDcard and on fitting it get curpath= 0:/ 0 Files. If I do a list(1) I get the 3 function names of files I tried to save to the original SD card but which did not show up under dir so I presume they must be in flash memory.

I have tried to use fmount in various ways but I always get error messages but the result of dir suggests the card is mounted anyway.

Also I cannot load any of the files from the original SD card but of course they are in BV basic which may prevent loading.
What I would like to know is how do I save files to the SD card. I have tried many ways without success. This is somewhat frustrating since it was all so easy under BV basic.

M Smith
Re: SD card files
March 16, 2013 08:43PM
I am disappointed no one has replied to my previous post. Despite more attempts I have still not being able to save a program file to the SD card on my BV513 nor have I been able to load one.
Some one must be able to do this; how about telling me how.

TIA
Malcolm Smith
Re: SD card files
March 18, 2013 02:02PM
hello,
The previous version 'tload' had the facility to load a basic file to SD Card. The new version uses 'bload' which will transfer any information to the SD Card not just .bas files, however you do need to enable the hardware handshaking for this as follows:

1) download the BV512_V2 program here:** This is now included in rookie ** see www.bypic.co.uk
2) run the code by typing bv513_rts
3) on the BV_COM menu Serial click on CTS

*** With CTS enabled on BV_COM communication will NOT work unless the bv513_rts is run and so when you come back next day after a reset it looks as though the device has broken, in other words don't forget that CTS is switched on ***

The process can be automated so that it is always on, if you download the bv513_rts program and then add:

function main()
  bv513_rts()
endf

Then type flsave("")

Loading has not changed except that load is now fload as all words are now prefixed with what they are associated with. To load a .bas file from the SD Card use fload("file name without .bas")



Edited 1 time(s). Last edit at 07/15/2014 06:22AM by jimeer.
Re: Bypic code
March 18, 2013 09:41PM
Thanks admin. I felt there was something missing but could not find out what.

M Smith
Re: Bypic code
March 22, 2013 11:48PM
Jim,
Sorry to say but I am getting into a mess here.
Followed your instructions about setting up of hand shaking but:-
I am using the bload icon on BV_comm2 (next to the Tload icon) and initially htought I had saved a file to the SD card.
On a closer look the function name showed up on DIR but the file was only 1 byte!. messed around and managed to delete ByPic so had to reload it using the Boot icon. More attempts to save to SD card have been unsuccesful and I have again had to re-install ByPic.
However this time when resetting it ends boot up with "General exception address 9d0054b0, reset required" which just keeps going round the loop? What is the answer? Restarting BV-Comm does not change anything.

Other q's
Should there be a send first string in the Bload window as there is in Tload?
List(x) works with 1 and 2, are there other ways of getting more info? it used to one could look at RAM or FLASH.
What is the significance of the "Start of P load" message that comes up after I think, fload("functionname").

Sorry for the workload.

Malcolm
Re: Bypic code
March 23, 2013 07:24AM
Malcolm,
1) When you re-load ByPic make sure the erase all flash is checked otherwise you can get a general exception error.
2) Make sure you follow the instructions about setting CTS on BV_COMM, also don't forget to type bv513_rts, unless its been put inmain and saved to flash
3) leave thesend first string blank
4) There are no more list commands, the code is now compiled so there is very little to list except machine code
5) No particular significance for message except it informs you that it is waiting for the download
Re: Bypic code
March 23, 2013 10:46PM
Thankyou Jim, that erasure sorted out the problem

Malcolm Smith
Re: Bypic code
April 27, 2013 10:26PM
I am now using the Rookie code on my 513v2.
I have been unable to get the code for flashing te onboard LED to compile.
Error message is io_setC(15,OUT) is undefined. I have tried adding constants that may be relevant
but without success.
Where am I going wrong. I can flash the LED using different code by the way.
Re: Bypic code
April 28, 2013 09:04AM
io_setC(15,OUT) is not a rookie command, see this link. It was a command for about a day or so but then evolved to what it is now so that it is consistant accross all BV5xx. Type flcear(0) and reload rookie to make sure you have the latest version.

led_on(), led_off() will operate the onboard LED on the latest version, see the link.
Re: Bypic code
April 28, 2013 11:22PM
Thankyou Jim.
That solved the problem. My Rookie firmware appears to be upto date, V2.1. However the downloaded paperwork I have appears to be out of date.
How can we track what is up-to-date?
Re: Bypic code
April 29, 2013 07:45AM
That is the reason I everything is on line, always check on line first.
Re: Bypic code
May 24, 2013 07:59PM
Re: BV523 Reset after Poff

After powering off on touch screen I wish to switch back on to continue
using touch screen where I left off at some random time in the future.
I assume the reset pin is designed for this. What is connected to pin 1, the reset pin?

Very pleased so far, can control output pins from screen. Great!

Awaiting advice John29.
Re: Bypic code
May 24, 2013 11:36PM
I am not sure I understand the question, a reset will do just that, reset the system back to the beginning and not where you left off; a function like that that would be called something like suspend wouldn’t it?
Re: Bypic code
May 25, 2013 06:48AM
Maybe going too far too soon with the question.
Just what do you connect to reset pin? to restart after poff.
Thanks for your quick reply.
All the best john29
Re: Bypic code
May 26, 2013 06:19PM
a push button to ground



Edited 1 time(s). Last edit at 05/26/2013 06:19PM by jimeer.
Re: Bypic code
June 11, 2013 10:23PM
I am altering the code for running the small keypad from pic32 basic to ByPic.
The line giving me a problem is :- p%=and(p%,0x0f)
My attempts :- p%=p% & 0x0f does not compile.
Nor does :- p%=(p% && 0x0f)
Can anyone give guidance?

thanks
Re: Bypic code
June 12, 2013 08:25AM
I think you are confusing the data types for the old BV_Basic with ByPic there is no unsigned variable that uses the % postfix so change this:
p%=p% & 0x0f

to this
p = p & 0x0f

The % is the modulus operator. Further details are Here in the language guide
Re: Bypic code
June 12, 2013 10:25PM
Thanks for that Jim.
I was blind to the obvious

Malcolm
Re: Bypic code
June 13, 2013 11:11PM
Using BVbasic scheduling was available using 'process'. What would provide a similar technique using ByPic.

Malcolm
Re: Bypic code
June 18, 2013 04:33PM
Thank you for the question. I have been asked this before, the short answer is that scheduling takes up too much processing time.

The long answer with an example of an alternative is here

The above is not only for scheduling but offers an alternative (better) way of organising code.
Re: Bypic code
September 29, 2013 09:59PM
I have been trying to convert the keyboard scanning program to Bypic code without success. So far I have not got the the first two functions to work as they should. Can anyone help.
Also when the keyword 'return' is used where is the variable returned to and how can it be accessed.

TMSmith
Re: Bypic code
September 30, 2013 07:20AM
Hello,
I think you need to be a bit more specific to get an answer to the first question but the answer to the second question is yes thus:

function twotimes(value)
  return value * 2
endf

function test()
  print twotimes(5)
endf

The first function return two times the value given and the second function prints it out.
Re: Bypic code
September 30, 2013 09:36PM
Jim.
The hardware is the 12 button keypad and my code fails to give the expected test results when testing kp_scan. ie. 240 and 14.
I believe the fault lies in these two functions. The original lines of code are left in but commented out. Some test code is still in place.
Your observations would be appreciated.
Malcolm

//KeyPad Initialissation
constant AD1PCFG% 0xbf809060
constant CPNUE% 0xbf8861e0
dim kp_count, kp_value, kp_ibptr, kp_obptr,kbuf(31)
// Initialise ports including setting the AtoD channels
// to digital
function kp_start()
    //poke(AD1PCFG%+8)=0x0f // just set the ones used 
    //poke(CPNUE%+8)=0x3c //  weak pull ups on CN5:2
    io_pinMode(PORTB,0,IN, WPU)  // port b 3:0 = i/p
    io_pinMode(PORTB,1,IN, WPU)  // port b 3:0 = i/p
    io_pinMode(PORTB,2,IN, WPU)  // port b 3:0 = i/p
    io_pinMode(PORTB,3,IN, WPU)  // port b 3:0 = i/p

    io_pinMode(PORTE,5,OUT, WOFF)  // port e 5:7 = o/p
    io_pinMode(PORTE,6,OUT, WOFF)  // port e 5:7 = o/p
    io_pinMode(PORTE,7,OUT, WOFF)  // port e 5:7 = o/p
    //portw "etc" 0xe0  // port e 7:5 = o/p
    //portw "eos" 0xe0  // all high
    io_setPort(PORTE,0xe0)
endf


// scans the keypad by successively lowering the column
// and checking port b for not being all high
// returns a code based on the input
#option echo on
function kp_scan()
dim i,p,r
    for i=1 to 3
       io_write(PORTE,4+i,LOW)
       p=io_read(PORTB,i)
       p = p & 0x0f
       io_write(PORTB,4+i,HIGH) // col 5-7 high
       if p <> 0x0f then break
       endif
    next
    r=p*i*i
    print r
    return r
endf



Edited 3 time(s). Last edit at 10/01/2013 07:26AM by admin.
Re: Bypic code
October 01, 2013 07:31AM
Malcolm,
there may be other errors but in this code:

       if p <> 0x0f then break
       endif
the break will have no effect, it should be on the next line thus:
       if p <> 0x0f then 
           break
       endif
This also applies to case statements which has caught me out before today.
Re: Bypic code
October 02, 2013 10:51PM
Thankyou Jim, written into Bypic keywords
Will try that tomorrow evening

Malcolm
Re: Bypic code
October 29, 2013 04:31PM
Hi Jim
About format$
in Documentation/Keywords/format$, I taking some examples
I have problems to format decimal places:

some examples in documentation do not work as expected

"
| ByPic Version 2.08
| Saves 0 |
| BV523 Serial# 201310020
| |
| Documentation www.bypic.co.uk |
| |
| Copyright Jim Spence 2013 |
======================================
0:/ ok dim f#

0:/ ok f#=123.779

0:/ ok print format$("number %f.2 ",f#)
ERROR (0) <f.> undefined function or variable at print

0:/ ok print format$(" number %f2 ",f#)
number 123.7790002
0:/ ok print format$(" number %d2 ",f#)
number 1232
0:/ ok print format$("n %f ",f#)
n 123.779000
0:/ ok print format$("n %g ",f#)
n [f5].67295e-319
0:/ ok print format$("n %d2.2 ",f#)
n 1232.2
0:/ ok
"
Please help me to use formatation for 2 decimal places

Bye
Sorry, you do not have permission to post/reply in this forum.