It is currently Tue Jun 18, 2013 3:51 pm

All times are UTC + 10 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Setting up code for other pic microcontrolers.
PostPosted: Sat Apr 21, 2012 1:12 pm 
Offline
semi-newbie
semi-newbie

Joined: Wed Nov 24, 2010 5:01 am
Posts: 10
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


Top
 Profile E-mail  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Sat Apr 21, 2012 7:14 pm 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 722
Location: United Kingdom
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:
   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:
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


Top
 Profile  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Tue Apr 24, 2012 4:01 am 
Offline
semi-newbie
semi-newbie

Joined: Wed Nov 24, 2010 5:01 am
Posts: 10
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:
     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?


Top
 Profile E-mail  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Tue Apr 24, 2012 4:12 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 722
Location: United Kingdom
Im glad you found it useful, I enjoy Swordfish way more than Assembly :)
Quote:
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:
Array(1) = 10
Array(2) = 10
Array(3) = 10
Array(4) = 10

Or something along the lines of this
Code:
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


Top
 Profile  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Tue Apr 24, 2012 4:19 am 
Offline
semi-newbie
semi-newbie

Joined: Wed Nov 24, 2010 5:01 am
Posts: 10
Quote:
Yep there is several ways you can do this..
you can initialise each Array element by
Code:
Array(1) = 10
Array(2) = 10
Array(3) = 10
Array(4) = 10

Or something along the lines of this
Code:
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:
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:
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


Top
 Profile E-mail  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Tue Apr 24, 2012 4:36 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 722
Location: United Kingdom
Quote:
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:
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)


Top
 Profile  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Tue Apr 24, 2012 6:26 am 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1893
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:
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.


Top
 Profile  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Tue Apr 24, 2012 2:36 pm 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1893
Or, you could be a little bit fancy and store the data in a single constant and then grab each bit from it.

Code:
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


Top
 Profile  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Sun May 13, 2012 8:54 am 
Offline
semi-newbie
semi-newbie

Joined: Wed Nov 24, 2010 5:01 am
Posts: 10
thanks alot for the help guys i was able to get my project working great now :] i will post some pics of it soon


Top
 Profile E-mail  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Sun May 13, 2012 8:58 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 722
Location: United Kingdom
Your welcome, look forward to seeing your project :)


Top
 Profile  
 
 Post subject: Re: Setting up code for other pic microcontrolers.
PostPosted: Sat May 19, 2012 1:42 pm 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1893
Me too!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 10 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme made by Keenen Wheeler