Setting up code for other pic microcontrolers.
Moderators: Chuckt, Garth, bitfogav
- waywardson07
- 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.
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
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
Re: Setting up code for other pic microcontrolers.
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:
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:
Gavin
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
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
- waywardson07
- 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.
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:
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?
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)
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?
Re: Setting up code for other pic microcontrolers.
Im glad you found it useful, I enjoy Swordfish way more than Assembly
you can initialise each Array element by
Or something along the lines of this
so each element of your array will now = 2

Yep there is several ways you can do this..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?
you can initialise each Array element by
Code: Select all
Array(1) = 10
Array(2) = 10
Array(3) = 10
Array(4) = 10
Code: Select all
dim Array(5) as byte
dim Index as byte
for Index = 0 to 5
Array(Index) = 2
next
- waywardson07
- 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.
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 asYep there is several ways you can do this..
you can initialise each Array element byOr something along the lines of thisCode: Select all
Array(1) = 10 Array(2) = 10 Array(3) = 10 Array(4) = 10
so each element of your array will now = 2Code: Select all
dim Array(5) as byte dim Index as byte for Index = 0 to 5 Array(Index) = 2 next
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)
Re: Setting up code for other pic microcontrolers.
Sadly in Swordfish you cant Intialise Arrays the same way as a Constant Array.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
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
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)
- brad
- 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.
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:
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.
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
- brad
- 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.
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
- waywardson07
- 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.
thanks alot for the help guys i was able to get my project working great now :] i will post some pics of it soon
Re: Setting up code for other pic microcontrolers.
Your welcome, look forward to seeing your project 

Who is online
Users browsing this forum: No registered users and 1 guest