There's no bank switching to worry about with the 18F1320 on the Junebug tutor.August Treubig said:Pic assembler is kinda strange because of "bank switching, etc"
{
*****************************************************************************
* Name : BLINK_1.BAS *
* Author : William Richardson *
* Notice : Copyright (c) 2008 blueroomelectronics *
* : All Rights Reserved *
* Date : 1/7/2008 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F1320
Clock = 4 // 4MHz clock
Include "junebug.bas"
Dim Count As Byte
While True
For Count = 0 To 6
LED(Count)
DelayMS(300) // delay in 1000s of a second
Next
Wend // repeat forever
End
{
*****************************************************************************
* Name : JUNEBUG.BAS *
* Author : William Richardson *
* Notice : Copyright (c) 2008 blueroomelectronics *
* : All Rights Reserved *
* Date : 2/1/2008 *
* Version : 0.92beta *
* Notes : *
* : *
*****************************************************************************
}
Module Junebug
Device = 18F1320
Public Sub LED(x As Byte)
Select x
Case 1 // LED 1
TRISA.7 = 1
High(PORTA.0)
Low (PORTA.6)
Case 2 // LED 2
TRISA.7 = 1
Low (PORTA.0)
High(PORTA.6)
Case 3 // LED 3
TRISA.0 = 1
High(PORTA.6)
Low (PORTA.7)
Case 4 // LED 4
TRISA.0 = 1
Low (PORTA.6)
High(PORTA.7)
Case 5 // LED 5
TRISA.6 = 1
Low (PORTA.0)
High(PORTA.7)
Case 6 // LED 6
TRISA.6 = 1
High(PORTA.0)
Low (PORTA.7)
Else // All LEDs Off
TRISA.0 = 1
TRISA.6 = 1
TRISA.7 = 1
End Select
End Sub
Config OSC = INTIO2, WDT = OFF, LVP = OFF
ADCON1 = %11110101
OSCCON = $62 // 4 MHz clock
I have to somewhat agree. Their asm is a bit funky. But it's not SO terribly different from other assembly languages that I wasn't able to pick it up pretty quickly (coming from mostly Motorola assembly language background).August Treubig said:Futz, everything about PIC assembler is weird.
Not for me. I love assembler.RISC stuff is better done in a "higher" language.
// *** C18 Junebug 18F1320 LED
//
// THIS PROGRAM MAKE TWO LEDs WALK ACROSS THE JUNEBUG AND BACK
// NOTE: Project requires a linker scrpt.
// Add either 18f1320i.lkr (for debug) or 18f1320.lkr (no debug) to your project.
//
// BY RHIANNON
#pragma config OSC = INTIO2, WDT = OFF, LVP = OFF, DEBUG = ON
#include <p18f1320.h>
#define byte unsigned short
#define LED_ON_FOR 50
const byte valA[] = {0b00000001,0b01000000,0b01000000,0b10000000,0b10000000,0b00000001};
const byte dirA[] = {0b10111110,0b10111110,0b00111111,0b00111111,0b01111110,0b01111110};
void lightTwo(int first)
{
int onCount,blinky;
for(onCount=0; onCount<LED_ON_FOR; onCount++)
{
for(blinky=first; blinky<(first+2); blinky++)
{
LATA=valA[blinky];
TRISA=dirA[blinky];
}
}
}
void main(void)
{
int idx;
for(idx=0;idx<5;idx++)
{
lightTwo(idx);
}
for(idx=3;idx>0;idx--)
{
lightTwo(idx);
}
}
strokedmaro said:Maybe I'm a little out of my league....I have the manuals and I know the demo is in the manual but I have no Idea with what program in what order it takes to get it back on the PIC. Before buying the junebug I read the student guide from Parallax called "whats a micro controller" and it was very informative. Thats the first time I started understand what was going on and it was broken down into easy steps with good explanations.
I guess I will keep reading but what would you suggest I start with? Tell me what to read first and I will start there.
3v0 said:This a C18 Junebug program written by one of the students I tutor. I am not saying she started from scratch or wrote it without guidance. She does however understand what each line does. Not bad for 12.
blueroomelectronics said:Tell her well done, I'm several times that age and I'm just starting out with C18. I may take a peek at C30 as I can't figure out MPASM30...
blueroomelectronics said:Then try Swordfish BASIC SE, it has everything you need to get your feet wet. I've got a small LED module written for the Junebugs tutor.
The very simple blink program
Code:{ ***************************************************************************** * Name : BLINK_1.BAS * * Author : William Richardson * * Notice : Copyright (c) 2008 blueroomelectronics * * : All Rights Reserved * * Date : 1/7/2008 * * Version : 1.0 * * Notes : * * : * ***************************************************************************** } Device = 18F1320 Clock = 4 // 4MHz clock Include "junebug.bas" Dim Count As Byte While True For Count = 0 To 6 LED(Count) DelayMS(300) // delay in 1000s of a second Next Wend // repeat forever End
And the Junebug module
Code:{ ***************************************************************************** * Name : JUNEBUG.BAS * * Author : William Richardson * * Notice : Copyright (c) 2008 blueroomelectronics * * : All Rights Reserved * * Date : 2/1/2008 * * Version : 0.92beta * * Notes : * * : * ***************************************************************************** } Module Junebug Device = 18F1320 Public Sub LED(x As Byte) Select x Case 1 // LED 1 TRISA.7 = 1 High(PORTA.0) Low (PORTA.6) Case 2 // LED 2 TRISA.7 = 1 Low (PORTA.0) High(PORTA.6) Case 3 // LED 3 TRISA.0 = 1 High(PORTA.6) Low (PORTA.7) Case 4 // LED 4 TRISA.0 = 1 Low (PORTA.6) High(PORTA.7) Case 5 // LED 5 TRISA.6 = 1 Low (PORTA.0) High(PORTA.7) Case 6 // LED 6 TRISA.6 = 1 High(PORTA.0) Low (PORTA.7) Else // All LEDs Off TRISA.0 = 1 TRISA.6 = 1 TRISA.7 = 1 End Select End Sub Config OSC = INTIO2, WDT = OFF, LVP = OFF ADCON1 = %11110101 OSCCON = $62 // 4 MHz clock
;*** blackbox.asm demonstrates use of the debugger
;*** Junebug DIP switches 1,2,3 on all others off
;*** uses pushbuttons 1,2 and 3 (RB0, RB2 and RB5)
;*** a PORTB Watch window will update in Animate mode
list p=18F1320
include <p18F1320.inc>
CONFIG OSC=INTIO2,WDT=OFF,LVP=OFF
org 0x00 ; reset vector
movlw 0x72 ;
movwf OSCCON ; 8MHz internal osc
setf ADCON1 ; set all I/O to digital
bcf INTCON2,RBPU ; enable PORTB input pullups
bra $ ; loop forever
END
{
*****************************************************************************
* Name : BLINK_1.BAS *
* Author : William Richardson *
* Notice : Copyright (c) 2008 blueroomelectronics *
* : All Rights Reserved *
* Date : 1/7/2008 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F1320
Clock = 4 // 4MHz clock
Include "junebug.bas"
Dim Keys As Byte,Lit As Byte
While True
Keys=ReadKeys //get the key value
If Keys<>0 Then //any key pressed?
Lit=Lit And 1 Xor 1 //keep bottom bit and toggle it
Keys=Keys-1<<1 //keys = 0,2 or 4
Lit=Lit+Keys //combine them
EndIf
LED(Lit+1) //turn on the LED
DelayMS(10) // delay in 1000s of a second
Wend // repeat forever
End
{
*****************************************************************************
* Name : JUNEBUG.BAS *
* Author : William Richardson *
* Notice : Copyright (c) 2008 blueroomelectronics *
* : All Rights Reserved *
* Date : 2/1/2008 *
* Version : 0.92beta *
* Notes : *
* : *
*****************************************************************************
}
Module Junebug
Device = 18F1320
Public Sub LED(x As Byte)
Select x
Case 1 // LED 1
TRISA.7 = 1
High(PORTA.0)
Low (PORTA.6)
Case 2 // LED 2
TRISA.7 = 1
Low (PORTA.0)
High(PORTA.6)
Case 3 // LED 3
TRISA.0 = 1
High(PORTA.6)
Low (PORTA.7)
Case 4 // LED 4
TRISA.0 = 1
Low (PORTA.6)
High(PORTA.7)
Case 5 // LED 5
TRISA.6 = 1
Low (PORTA.0)
High(PORTA.7)
Case 6 // LED 6
TRISA.6 = 1
High(PORTA.0)
Low (PORTA.7)
Else // All LEDs Off
TRISA.0 = 1
TRISA.6 = 1
TRISA.7 = 1
End Select
End Sub
Function GetBit(Bin As Byte) As Byte
Dim I As Byte
GetBit=0
For I=1 To 8
If ((Bin And 1) = 1) Then
GetBit=I
EndIf
Bin=Bin>>1
Next
End Function
Dim OldKeys As Byte
Dim OldEdges As Byte
Dim KeyCount As Byte
Const KeyDelay=30 //initial delay before repeating in 10mS
Const KeyRepeat = 12 //repeat delay in 10mS
Public Function ReadKeys() As Byte
Dim Keys As Byte
Dim Edges As Byte
INTCON2.7=0 //WPUs on port B
ReadKeys=0 //return Zeor unless key pressed
Keys=0
If(PORTB.0=0) Then //move from port B to Keys
Keys=Keys Or 1
EndIf
If(PORTB.2=0) Then
Keys=Keys Or 2
EndIf
If(PORTB.5=0) Then
Keys=Keys Or 4
EndIf
Edges=(Keys Xor OldKeys) And Keys //edges contains new key presses
If Edges <> 0 Then //if new keypress
OldEdges=Edges //keep copy of it for repeating
KeyCount=KeyDelay //set initial delay
ReadKeys=GetBit(Edges) //return key number
EndIf
If Keys<>0 Then //repeating?
KeyCount=KeyCount-1 //Yes, so count down
If(KeyCount=0) Then //time to repeat yet?
ReadKeys=GetBit(OldEdges) //yes, return key number
KeyCount=KeyRepeat //set repeat count
EndIf
EndIf
OldKeys=Keys //keep copy for next time
End Function
Config OSC = INTIO2, WDT = OFF, LVP = OFF
ADCON1 = %11110101
OSCCON = $62 // 4 MHz clock
Device = 18F1320
Clock = 4
// alias to port pin...
Dim LEDA As PORTA.0
Dim LEDB As PORTA.1
// main program...
Low(LEDA)
Low(LEDB)
Repeat
Toggle (LEDA)
DelayMS (500)
Low(LEDA)
Toggle (LEDB)
DelayMS (500)
Low(LEDB)
Until false
Device = 18F1320
Clock = 4
// alias to port pin...
Dim LEDA As PORTA.0
Dim LEDB As PORTA.1
const intHigh = 2 // interrupt on INTCON bit:0 ? I think ? or any intcon with a HIGH
interrupt OnTimer(intHigh) //Button is pressed on INTCON/PORTB:0 i think? or any intcon with a HIGH
Low(LEDA)
Toggle (LEDB)
DelayMS (1000)
Low(LEDB)
end interrupt
// main program...
Low(LEDA)
Low(LEDB)
Repeat
Toggle (LEDA)
DelayMS (500)
Low(LEDA)
Until false
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?