Help with other switching to other types of pic controllers
Moderators: Chuckt, Garth, bitfogav
- 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: Help with other switching to other types of pic controll
Unfortunately I have not used that pic in MPLAB. Have you downloaded the data sheet for your PIC? Did you also incorporate the correct include file?
Re: Help with other switching to other types of pic controll
Using ASM and mplab for 18F devices is not an easy task!.. But theres two ways of setting the Config bits in MPLAB.MrDEB wrote:I am trying to learn ASM but using a different pic instead of the 16F684a.
I have a developement board (TAP-28) with an 18F2420. I have looked all over the data sheet for the config settings but?? maybe looking for the wrong thing. Right Church, Wrong Pew.
I am starting out with the LED flasher that I downloaded for tutorial 2.
Firstly you need to set the device under the "Configure" tab.
Then you can set the Config settings in code or using the Configuration Bits under the "Configure" tab.
If you set them in Code then it should look something like this: (NOTE this is some config settings for a 18F4550)
Code: Select all
CONFIG PLLDIV = 5 ; Divide by 5 (20 MHz oscillator input)
CONFIG CPUDIV = OSC1_PLL2 ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
CONFIG USBDIV = 2 ; USB from the 96 MHz PLL divided by 2
CONFIG FOSC = HSPLL_HS ; HS oscillator, PLL enabled, HS used by USB
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Oscillator Switchover mode disabled
CONFIG PWRT = ON ; PWRT enabled
CONFIG BOR = OFF ; Brown-out Reset enabled in hardware only
CONFIG BORV = 2 ; Brown-out Voltage medium setting
CONFIG VREGEN = ON ; USB voltage regulator enabled
CONFIG WDT = OFF ; HW Disabled - SW Controlled
CONFIG WDTPS = 32768 ; Watch-dog timer set to 256*4ms = 1s
CONFIG MCLRE = OFF ; MCLR pin enabled; RE3 input pin disabled
CONFIG LPT1OSC = OFF ; Timer1 configured for higher power operation
CONFIG PBADEN = OFF ; PORTB<4:0> pins are digital I/O on Reset
CONFIG CCP2MX = ON ; CCP2 input/output is multiplexed with RB3
CONFIG STVREN = ON ; Stack full/underflow will not cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
; 18F4x5x TQFP only CONFIG ICPRT = OFF ; ICPORT disabled
CONFIG XINST = OFF ; Instruction set extension disabled
CONFIG DEBUG = OFF ; RB6 and RB7 are general purpose I/O pins
CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected
CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
CONFIG CPD = OFF ; Data EEPROM not code-protected
CONFIG WRT0 = ON ; Block 0 (000800-001FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
CONFIG WRTB = ON ; Boot block (000000-0007FFh) IS write-protected
CONFIG WRTC = OFF ; Configuration (300000-3000FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 not protected from table reads
CONFIG EBTR1 = OFF ; Block 1 not protected from table reads
CONFIG EBTR2 = OFF ; Block 2 not protected from table reads
CONFIG EBTR3 = OFF ; Block 3 not protected from table reads
CONFIG EBTRB = OFF ; Boot block protected from table reads
If you don't know what Voltage your country is using, you shouldn't be doing electronics
-
- I practically live here!
- Posts: 372
- Joined: Fri Feb 18, 2011 4:24 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: Help with other switching to other types of pic controll
Now I see why you don't use ASM in MPLAB for 18F pics'
I do have a 16F84a on hand I purchased for ?? but its an 18pin device so on to bread-boarding instead of using the Tap28.
This should get me going as in the end I just want to control a tri color LED to simulate a candle flicker. I have a SWORDFISH code that uses a random number generator that I pieced together from several different code examples.
I do have a 16F84a on hand I purchased for ?? but its an 18pin device so on to bread-boarding instead of using the Tap28.
This should get me going as in the end I just want to control a tri color LED to simulate a candle flicker. I have a SWORDFISH code that uses a random number generator that I pieced together from several different code examples.
Code: Select all
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : Doug Bezaire *
* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 3/26/2010 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F2420
Clock = 8
Include "InternalOscillator.bas"
Include "RandGen.bas"
Include "Utils.bas"
Dim TMR2IE As PIE1.1, // TMR2 interrupt enable
TMR2IF As PIR1.1, // TMR2 overflow flag
TMR2ON As T2CON.2, // Enables TMR2 to begin incrementing
Signal_Pin As PORTB.0 // Signal output to frequency meter
Dim Red_Pin As PORTA.0, //was b.0
Green_Pin As PORTA.1, //was b1
Blue_Pin As PORTA.2, //was b2
Red_Duty As Byte,
Green_Duty As Byte,
Blue_Duty As Byte,
Red_DutyVal As Byte,
Green_DutyVal As Byte,
Blue_DutyVal As Byte,
RandomVal As Byte
Dim uS As Word,
mS As Word
// ranval(1)as word
Interrupt TMR2_Interrupt()
High(Signal_Pin)
Save(0) // Back up system variables
If TMR2IF = 1 Then // Check if the interrupt was from TMR2
TMR2IF = 0 // Clear the TMR2 interrupt flag
uS = uS + 50
If uS >= 1000 Then
uS = uS - 1000
Inc(mS)
EndIf
Inc(Red_DutyVal)
Inc(Green_DutyVal)
Inc(Blue_DutyVal)
If Red_DutyVal > Red_Duty Or Red_Duty = 0 Then
Red_Pin = 0
Else
Red_Pin = 1
EndIf
If Green_DutyVal > Green_Duty Or Green_Duty = 0 Then
Green_Pin = 0
Else
Green_Pin = 1
EndIf
If Blue_DutyVal > Blue_Duty Or Blue_Duty = 0 Then
Blue_Pin = 0
Else
Blue_Pin = 1
EndIf
EndIf //
Restore // Restore system variables
Low(Signal_Pin)
End Interrupt
Private Sub TMR2_Initialize()
TMR2ON = 0 // Disable TMR2
TMR2IE = 0 // Turn off TMR2 interrupts
PR2 = 149 // TMR2 Period register PR2
T2CON = %00000001 // T2CON 0:1 = Prescale
// 00 = Prescale is 1:1
// 01 = Prescale is 1:4
// 1x = Prescale is 1:16
// 3:6 = Postscale
// 0000 = 1:1 postscale
// 0001 = 1:2 postscale
// 0010 = 1:3 postscale...
// 1111 = 1:16 postscale
TMR2 = 0 // Reset TMR2 Value
TMR2IE = 1 // Enable TMR2 interrupts
TMR2ON = 1 // Enable TMR2 to increment
Enable(TMR2_Interrupt)
End Sub
// Start Of Program...
Low(Red_Pin)
Low(Green_Pin)
Low(Blue_Pin)
Red_Duty = 30
Green_Duty = 10
Blue_Duty = 5
Red_DutyVal = 0
Green_DutyVal = 0
Blue_DutyVal =0
uS = 0
mS = 0
RandGen.Initialize(128) // Initialize the Random Number generator
TMR2_Initialize // Setup and enable TMR2
While True // Create an infinite loop
RandomVal = RandGen.Rand // Grab a random number from 0 to 255
// Select RandomVal // Find out what colour to increase/decrease
//Case 0 To 42
Red_Duty =RandomVal-5
//mS = 0
// (Red_Duty)=Rand(1)
// Repeat
// Until mS = 19
// and Red_Duty>0
// endif
//Case 43 To 84
If Red_Duty > 0
Then mS = 0
Repeat
Until mS = 19
Dec(Red_Duty)
EndIf
// Case 84 To 127
Green_Duty =RandomVal-20
//Then mS = 0
// Repeat
// Until mS = 19
// Inc(Green_Duty)
// EndIf
// Case 128 To 170
If Green_Duty > 0
Then mS = 0
Repeat
Until mS = 19
Dec(Green_Duty)
EndIf
// Case 170 To 212
Blue_Duty = RandomVal-30
// Then mS = 0
// Repeat
// Until mS = 19
// Inc(Blue_Duty)
// EndIf
// Case 212 To 255
If Blue_Duty > 0
Then mS = 0
Repeat
Until mS = 19
Dec(Blue_Duty)
EndIf
Wend
End
- 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: Help with other switching to other types of pic controll
That's a great ideabut personally I avoid using ASM for 18F and keep that to Swordfish.
I am certainly glad that I first learned ASM though because once I then moved onto swordfish basic, I got a very good appreciation for how nice it is to have use a high level language, I have not turned back to ASM.
So I guess what I'm saying is, if I had learned Swordfish first, I may never have had the desire to go and learn ASM!
-
- Can't get enough of electronics!
- Posts: 83
- Joined: Mon Aug 30, 2010 8:05 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: Help with other switching to other types of pic controll
I am many years late to this party but if Jumbosize is by any chance still curious I had a similar problem when I tried to use the LED flasher code Brad provided with a 12f615, my problem was in the cblock h'20' directive where you declare the delay constants since in my case the memory locations for the general purpose registers didnt start until h'40' so the LED was constantly on since there were no registers holding the values for the delays.
Hopefully it is not too late...
Hopefully it is not too late...
Who is online
Users browsing this forum: No registered users and 4 guests