Setting up code for other pic microcontrolers.

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
waywardson07
decided to stick around...
decided to stick around...
Posts: 25
Joined: Wed Nov 24, 2010 5:01 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Setting up code for other pic microcontrolers.

Post by waywardson07 » Sat Apr 21, 2012 1:12 pm

hi brad!
i wanted to ask if you would be able to help me get my chip working.
i have been messing around with this 18f4680 and cant seem to get it to work.

do you think it would be possible to help me with this problem?

what i need to know is how to start my code.

i know i first set witch chip im using

LIST p=18f4680
include "P18f4680.inc"

but from there im not to sure how to set the default configuration and set my PORTB to outputs.

i would be happy to get a single led to flash and from there i can move foreward

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Setting up code for other pic microcontrolers.

Post by bitfogav » Sat Apr 21, 2012 7:14 pm

I think Brad would agree with me if you are a beginner, the 18F microchip is a powerful microchip, I would look at using the Swordfish language especially has you are using a 18F microcontroller, Swordfish Basic is dedicated the 18F family of the microchip.

For Assembly Language you would probably need something like this after
LIST p=18f4680
include "P18f4680.inc"

Example:

Code: Select all

	CONFIG WDT=OFF     ; disable watchdog timer
	CONFIG MCLRE = ON  ; MCLEAR Pin on
	CONFIG DEBUG = ON  ; Enable Debug Mode
	CONFIG LVP = OFF    ; Low-Voltage programming disabled (necessary for debugging)
	CONFIG FOSC = INTOSCIO_EC  ;Internal oscillator, port function on RA6
Look here!:
Swordfish IDE

You can also get a free version of the IDE which is only limited to the amount of RAM you can use!
which you can find here:
Swordfish SE

If you really want to get into Swordfish then you can find some great Code examples here Digital-DIY.com:
SF Code Examples

The code for flashing a LED is simple has this:

Code: Select all

Device = 18F4680
Clock = 8
Config OSC = INTIO67                // Use the Internal Oscillator 
Include "utils.bas" 

Dim LED As PORTA.0                  // Assign an alias for "LED" 
// Start Of Program...
OSCCON = %01111111                  // Sets up the internal oscillator 
SetAllDigital                       // Make all Pins digital I/O's
									
Low(LED)                            // Make the LED pin an output and set it low 

While True     
High(Led)                          // Turn on the LED     
DelayMS(500) 	                   // Delay for half a second     
Low(Led)        	                // Turn off the LED     
DelayMS(500)                       // Delay for half a second 
Gavin

User avatar
waywardson07
decided to stick around...
decided to stick around...
Posts: 25
Joined: Wed Nov 24, 2010 5:01 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Setting up code for other pic microcontrolers.

Post by waywardson07 » Tue Apr 24, 2012 4:01 am

wow thanks for the help.
i am using the swordfish ide now. it works great!

i have only one problem im running in to...

i am able to declare and initialize a constant array in a single line of code like this:

Code: Select all

     const array(5) as bit = (0,0,0,0,0)
but that does not work for the variable array.
i can declare it but there is no way to initialize all its members in one go like the constant array.

is there a way around this?

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Setting up code for other pic microcontrolers.

Post by bitfogav » Tue Apr 24, 2012 4:12 am

Im glad you found it useful, I enjoy Swordfish way more than Assembly :)
i have only one problem im running in to...
i am able to declare and initialize a constant array in a single line of code like this:
Code:
const array(5) as bit = (0,0,0,0,0)
but that does not work for the variable array.
i can declare it but there is no way to initialize all its members in one go like the constant array.
is there a way around this?
Yep there is several ways you can do this..
you can initialise each Array element by

Code: Select all

Array(1) = 10
Array(2) = 10
Array(3) = 10
Array(4) = 10
Or something along the lines of this

Code: Select all

dim Array(5) as byte
dim Index as byte
for Index = 0 to 5
   Array(Index) = 2
next 
so each element of your array will now = 2

User avatar
waywardson07
decided to stick around...
decided to stick around...
Posts: 25
Joined: Wed Nov 24, 2010 5:01 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Setting up code for other pic microcontrolers.

Post by waywardson07 » Tue Apr 24, 2012 4:19 am

Yep there is several ways you can do this..
you can initialise each Array element by

Code: Select all

Array(1) = 10
Array(2) = 10
Array(3) = 10
Array(4) = 10
Or something along the lines of this

Code: Select all

dim Array(5) as byte
dim Index as byte
for Index = 0 to 5
   Array(Index) = 2
next 
so each element of your array will now = 2
but lets say i wanted the array to hold data that is not all the same and it was a very large array so i didn't want to write it as

Code: Select all

Array(1) = 0
Array(2) = 1
Array(3) = 1
Array(4) = 0
etc...
Array(30) = 1

cause that would take up too many lines as apposed to

Code: Select all

dim Array(16) as bit = (0,0,0,1,1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0)
but the above code is not valid

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Setting up code for other pic microcontrolers.

Post by bitfogav » Tue Apr 24, 2012 4:36 am

but lets say i wanted the array to hold data that is not all the same and it was a very large array so i didn't want to write it as
Array(1) = 0
Array(2) = 1
Array(3) = 1
Array(4) = 0
etc...
Array(30) = 1
cause that would take up too many lines as apposed to
dim Array(16) as bit = (0,0,0,1,1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0)
but the above code is not valid
Sadly in Swordfish you cant Intialise Arrays the same way as a Constant Array.
So we are either left with typing out every line of the Array or we use a Repetitive statement for example a FOR Loop.

It looks like you have an Bit Array so something like this?

Code: Select all

Dim Index as byte
Dim Array(16) as bit

For Index = 0 to bound(Array)
    If Index = 1 Or Index = 2 Or Index = 4 Or Index = 9 Or Index = 16 then
        Array(Index) = 1
    Else
        Array(Index) = 0
    EndIf
Next
So in the example above. Array(1),Array(2),Array(4),Array(9),Array(16) = 1
all other Array elements will = 0

Note that the first element of an array is located at 0, the second element at 1 and so on. Because Swordfish arrays begin with zero indexes.
so the Array code above will output something like this (0,1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,1)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Setting up code for other pic microcontrolers.

Post by brad » Tue Apr 24, 2012 6:26 am

This is how I do it:

I set up a constant array with my data, then my variable arrays (which will initially contain no data) I then run a loop to fill the variables with data from my const array:

Code: Select all

const MyData(8) as bit = (1, 0, 1, 1, 0, 0, 0, 1)
dim MyVariableData(8) as bit
dim x as byte

for x  = 0 to 7
     MyVariableData(x) = MyData(x)
next
Swordfish is a fantastic language. I am working on a project at the moment using swordfish and it is alot more fun and fluid than assembly.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Setting up code for other pic microcontrolers.

Post by brad » Tue Apr 24, 2012 2:36 pm

Or, you could be a little bit fancy and store the data in a single constant and then grab each bit from it.

Code: Select all

Const MyData as word = %1011101001001011

Dim MyVariable(16) as bit
Dim x as byte

For x = 0 to 15
     MyVariable(x) = MyData.bits(x)
Next

User avatar
waywardson07
decided to stick around...
decided to stick around...
Posts: 25
Joined: Wed Nov 24, 2010 5:01 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Setting up code for other pic microcontrolers.

Post by waywardson07 » Sun May 13, 2012 8:54 am

thanks alot for the help guys i was able to get my project working great now :] i will post some pics of it soon

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Setting up code for other pic microcontrolers.

Post by bitfogav » Sun May 13, 2012 8:58 am

Your welcome, look forward to seeing your project :)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Setting up code for other pic microcontrolers.

Post by brad » Sat May 19, 2012 1:42 pm

Me too!

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 14 guests