Moving onto greener pastures!
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
Moving onto greener pastures!
Hello fellow programmers!
I am actually going to do it - I am learning a new programming language for pic microcontrollers.
BASIC!
I was actually thinking of programming in C but I have looked right into basic and think that's for me. It's amazing how much more powerful the language is compared to ASM.
I am really looking forward to it and for starters I think I will look at porting my old projects over to picbasic code.
If anyone wants to join me in my endeavor then feel free, otherwise I'll just let you know how it is coming along for me.
I am actually going to do it - I am learning a new programming language for pic microcontrollers.
BASIC!
I was actually thinking of programming in C but I have looked right into basic and think that's for me. It's amazing how much more powerful the language is compared to ASM.
I am really looking forward to it and for starters I think I will look at porting my old projects over to picbasic code.
If anyone wants to join me in my endeavor then feel free, otherwise I'll just let you know how it is coming along for me.
- sdudley
- Moderator
- Posts: 337
- Joined: Sun Mar 28, 2010 1:33 pm
- Location: Florida, U.S.A. [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
TRAITOR! 

Last edited by sdudley on Thu Jun 10, 2010 9:21 pm, edited 1 time in total.
Any time you deviate from sequential consistency, you increase the complexity of the problem by orders of magnitude.
- 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
I now realize that I have given you too much power...
But on another note. I really have hit a wall with assembly so I would like to see if I can make bigger and better things with a language that can help me achieve that.
This program I am using is great. You code in basic and when you compile it, it actually gives you the hex and also asm output. It's interesting to see how 10 lines of basic turn into about 100 in assembly
But on another note. I really have hit a wall with assembly so I would like to see if I can make bigger and better things with a language that can help me achieve that.
This program I am using is great. You code in basic and when you compile it, it actually gives you the hex and also asm output. It's interesting to see how 10 lines of basic turn into about 100 in assembly
- sdudley
- Moderator
- Posts: 337
- Joined: Sun Mar 28, 2010 1:33 pm
- Location: Florida, U.S.A. [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
WOW, what an ego!brad wrote:...I really have hit a wall with assembly so I would like to see if I can make bigger and better things with a language that can help me achieve that...

Ok, just kidding! Really.

On a serious note, would you consider dedicating a forum topic to discussing basic code, etc. It's interesting you note this because I have taken one class in "Visual Basic" and really enjoyed that. There are two more classes available at the community college I attend. At one time I was planning on taking them but decided not to because I am drowning in projects (and work) as it is!
Also, we had discussed doing that little "C" course together so I figured that might be the way to go.
However... Now that I see someone else is interested in basic, then I might drum up more interest myself (yes, I am a follower not a leader).
With all that said, I really enjoy assembly and have not felt the need to move on just yet. There is still MUCH MUCH more for this young Jedi to learn and to become a master are many light years yet away!
Stacy
Any time you deviate from sequential consistency, you increase the complexity of the problem by orders of magnitude.
What is the name of the program that you are using for BASIC?brad wrote:I now realize that I have given you too much power...
But on another note. I really have hit a wall with assembly so I would like to see if I can make bigger and better things with a language that can help me achieve that.
This program I am using is great. You code in basic and when you compile it, it actually gives you the hex and also asm output. It's interesting to see how 10 lines of basic turn into about 100 in assembly
- 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
Yesterday basically confirmed it for me.
I was programming a 24 x 24 led matrix that I had made for work and I wanted to try and manipulate some graphics. (I.E. make the turn around or morph a little bit etc...) but it is just so hard in assembly. (so, so hard!)
I was looking into C, but from what I have seen - Basic is a far better way to go.
The program I am using is called swordfish, you can either get the free version or the paid version (which is around $150)
Having said that, the only difference between the two is that the free version has a variable limit of 200. But that is ALOT of variables! I don't think I would ever need to use 200 variables.
Take this for example - Here is a Basic program that will display "Analog input AN0" on one of those 16x2 LCD displays.
Once compiled, it also gives me the equivalent assembly code:
That's alot of code!
I was programming a 24 x 24 led matrix that I had made for work and I wanted to try and manipulate some graphics. (I.E. make the turn around or morph a little bit etc...) but it is just so hard in assembly. (so, so hard!)
I was looking into C, but from what I have seen - Basic is a far better way to go.
The program I am using is called swordfish, you can either get the free version or the paid version (which is around $150)
Having said that, the only difference between the two is that the free version has a variable limit of 200. But that is ALOT of variables! I don't think I would ever need to use 200 variables.
Take this for example - Here is a Basic program that will display "Analog input AN0" on one of those 16x2 LCD displays.
Code: Select all
Define LCD_BITS = 8 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 1
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
Define LCD_RWREG = PORTD 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 2 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
Dim an0 As Word
AllDigital 'configure all pins for digital use
ADCON1 = 0x0e 'configure AN0 input for analog use
Lcdinit 1 'initialize LCD module; cursor is blinking
loop:
Adcin 0, an0
Lcdcmdout LcdClear 'clear LCD display
Lcdout "Analog input AN0" 'text for the line 1
Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
Lcdout "Value: ", #an0 'formatted text for line 2
WaitMs 1 'larger value should be used in real device
Goto loop 'loop forever
Code: Select all
; Compiled with: PIC18 Simulator IDE - Evaluation Copy v2.76
; Microcontroller model: PIC18F4520
; Clock frequency: 8.0 MHz
;
; The address of 'an0' (word) (global) is 0x014
an0 EQU 0x014
; Begin
R0L EQU 0x000
R0H EQU 0x001
R1L EQU 0x002
R1H EQU 0x003
R2L EQU 0x004
R2H EQU 0x005
R3L EQU 0x006
R3H EQU 0x007
R4L EQU 0x008
R4H EQU 0x009
R5L EQU 0x00A
R5H EQU 0x00B
R6L EQU 0x00C
R6H EQU 0x00D
R7L EQU 0x00E
R7H EQU 0x00F
R8L EQU 0x010
R8H EQU 0x011
R9L EQU 0x012
R9H EQU 0x013
ORG 0x000000
BSF RCON,IPEN
GOTO L0002
ORG 0x000008
RETFIE FAST
ORG 0x000018
RETFIE FAST
; Begin of program
L0002:
; 1: Define LCD_BITS = 8 'allowed values are 4 and 8 - the number of data interface lines
; 2: Define LCD_DREG = PORTB
; 3: Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
; 4: Define LCD_RSREG = PORTD
; 5: Define LCD_RSBIT = 1
; 6: Define LCD_EREG = PORTD
; 7: Define LCD_EBIT = 3
; 8: Define LCD_RWREG = PORTD 'set to 0 if not used, 0 is default
; 9: Define LCD_RWBIT = 2 'set to 0 if not used, 0 is default
; 10: Define LCD_COMMANDUS = 2000 'delay after LCDCMDOUT, default value is 5000
; 11: Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
; 12: Define LCD_INITMS = 2 'delay used by LCDINIT, default value is 100
; 13: 'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
; 14:
; 15: Dim an0 As Word
; 16:
; 17: AllDigital 'configure all pins for digital use
MOVLW 0x0F
MOVWF 0xFC1
MOVLW 0x07
MOVWF 0xFB4
; 18: ADCON1 = 0x0e 'configure AN0 input for analog use
MOVLW 0x0E
MOVWF 0xFC1
; 19: Lcdinit 1 'initialize LCD module; cursor is blinking
BCF 0xF83,3
BCF 0xF83,1
BCF 0xF83,2
BCF 0xF95,3
BCF 0xF95,1
BCF 0xF95,2
CLRF 0xF93
MOVLW 0x02
MOVWF R0L
MOVLW 0x00
MOVWF R0H
CALL W001
MOVLW 0x33
CALL LC02
MOVLW 0x33
CALL LC02
MOVLW 0x33
CALL LC02
MOVLW 0x38
CALL LC02
MOVLW 0x0D
CALL LC02
MOVLW 0x01
CALL LC02
; 20:
; 21: loop:
L0001:
; 22: Adcin 0, an0
BSF ADCON2,ADFM
MOVLW 0x00
MOVWF R0L
CALL A001
MOVF ADRESL,W
MOVWF 0x014
MOVF ADRESH,W
MOVWF 0x015
; 23: Lcdcmdout LcdClear 'clear LCD display
MOVLW 0x01
CALL LC02
; 24: Lcdout "Analog input AN0" 'text for the line 1
MOVLW 0x41
CALL LC01
MOVLW 0x6E
CALL LC01
MOVLW 0x61
CALL LC01
MOVLW 0x6C
CALL LC01
MOVLW 0x6F
CALL LC01
MOVLW 0x67
CALL LC01
MOVLW 0x20
CALL LC01
MOVLW 0x69
CALL LC01
MOVLW 0x6E
CALL LC01
MOVLW 0x70
CALL LC01
MOVLW 0x75
CALL LC01
MOVLW 0x74
CALL LC01
MOVLW 0x20
CALL LC01
MOVLW 0x41
CALL LC01
MOVLW 0x4E
CALL LC01
MOVLW 0x30
CALL LC01
; 25: Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
MOVLW 0xC0
CALL LC02
; 26: Lcdout "Value: ", #an0 'formatted text for line 2
MOVLW 0x56
CALL LC01
MOVLW 0x61
CALL LC01
MOVLW 0x6C
CALL LC01
MOVLW 0x75
CALL LC01
MOVLW 0x65
CALL LC01
MOVLW 0x3A
CALL LC01
MOVLW 0x20
CALL LC01
MOVF 0x014,W
MOVWF R2L
MOVF 0x015,W
MOVWF R2H
CALL LC21
; 27: WaitMs 1 'larger value should be used in real device
MOVLW 0x01
MOVWF R0L
CLRF R0H
CALL W001
; 28: Goto loop 'loop forever
GOTO L0001
; End of program
L0003: BRA L0003
; Division Routine
D001: MOVLW 0x10
MOVWF R3L
CLRF R2H
CLRF R2L
D002: RLCF R0H,W
RLCF R2L,F
RLCF R2H,F
MOVF R1L,W
SUBWF R2L,F
MOVF R1H,W
BTFSS STATUS,C
INCFSZ R1H,W
SUBWF R2H,F
BTFSC STATUS,C
BRA D003
MOVF R1L,W
ADDWF R2L,F
MOVF R1H,W
BTFSC STATUS,C
INCFSZ R1H,W
ADDWF R2H,F
BCF STATUS,C
D003: RLCF R0L,F
RLCF R0H,F
DECFSZ R3L,F
BRA D002
MOVF R0L,W
RETURN
; Waitms Routine
W001: MOVF R0L,F
BTFSC STATUS,Z
BRA W002
RCALL W003
DECF R0L,F
NOP
NOP
NOP
NOP
NOP
BRA W001
W002: MOVF R0H,F
BTFSC STATUS,Z
RETURN
RCALL W003
DECF R0H,F
DECF R0L,F
BRA W001
W003: MOVLW 0x0C
MOVWF R2H
W004: DECFSZ R2H,F
BRA W004
NOP
NOP
MOVLW 0x26
MOVWF R1L
W005: DECFSZ R1L,F
BRA W006
RCALL W007
RCALL W007
NOP
NOP
RETURN
W006: RCALL W007
BRA W005
W007: MOVLW 0x0D
MOVWF R2L
W008: DECFSZ R2L,F
BRA W008
NOP
RETURN
; Waitus Routine - Byte Argument
X001: MOVLW 0x05
SUBWF R4L,F
BTFSS STATUS,C
RETURN
BRA X002
X002: MOVLW 0x03
SUBWF R4L,F
BTFSS STATUS,C
RETURN
BRA X002
; Waitus Routine - Word Argument
Y001: MOVLW 0x08
SUBWF R4L,F
CLRF WREG
BTFSS STATUS,C
ADDLW 0x01
SUBWF R4H,F
BTFSS STATUS,C
RETURN
BRA Y002
Y002: MOVLW 0x05
SUBWF R4L,F
CLRF WREG
BTFSS STATUS,C
ADDLW 0x01
SUBWF R4H,F
BTFSS STATUS,C
RETURN
BRA Y002
; Adcin Routine
A001: RLCF R0L,F
RLCF R0L,F
MOVLW 0x80
ANDWF ADCON2,F
MOVLW 0x3C
ANDWF R0L,W
IORLW 0x01
MOVWF ADCON0
MOVLW 0x03
IORWF ADCON2,F
MOVLW 0x14
MOVWF R4L
CALL X001
BSF ADCON0,GO
A002: BTFSC ADCON0,GO
BRA A002
BCF PIR1,ADIF
BCF ADCON0,ADON
RETURN
; Lcdout Routine
LC01: BSF 0xF83,1
BCF 0xF83,2
MOVWF 0xF81
RCALL LCX1
MOVLW 0x32
MOVWF R4L
CALL X001
RETURN
LCX1: BSF 0xF83,3
NOP
NOP
BCF 0xF83,3
NOP
NOP
RETURN
; Lcdcmdout Routine
LC02: BCF 0xF83,1
BCF 0xF83,2
MOVWF 0xF81
RCALL LCX1
MOVLW 0xD0
MOVWF R4L
MOVLW 0x07
MOVWF R4H
CALL Y001
RETURN
; Lcdout Decimal Conversion Routine
LC21: BSF R3H,7
MOVLW 0x27
MOVWF R1H
MOVLW 0x10
RCALL LC22
MOVLW 0x03
MOVWF R1H
MOVLW 0xE8
RCALL LC22
CLRF R1H
MOVLW 0x64
RCALL LC22
CLRF R1H
MOVLW 0x0A
RCALL LC22
MOVF R2L,W
BRA LC23
LC22: MOVWF R1L
MOVF R2H,W
MOVWF R0H
MOVF R2L,W
MOVWF R0L
CALL D001
MOVF R0L,W
BTFSS STATUS,Z
BCF R3H,7
BTFSC R3H,7
RETURN
LC23: ADDLW 0x30
CALL LC01
RETURN
; End of listing
END
- sdudley
- Moderator
- Posts: 337
- Joined: Sun Mar 28, 2010 1:33 pm
- Location: Florida, U.S.A. [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
MikroElectronica has some nice resources and offer free "online" books.
Here is a book on programming in basic:
http://www.mikroe.com/eng/products/view ... sic/#order
You can read the entire book online for FREE, or purchase a hard copy for $24.00!
They have several books available and all their books are very well explained, easy to read, and have FANTASTIC detailed graphic illustrations.
Here is the link to a book called PIC Microcontrollers:
http://www.mikroe.com/eng/categories/vi ... lications/
Here is the link to all the books they have available and several are free to read online. A wealth of knowledge at your finger tips!
http://www.mikroe.com/eng/categories/vi ... lications/
Stacy
Here is a book on programming in basic:
http://www.mikroe.com/eng/products/view ... sic/#order
You can read the entire book online for FREE, or purchase a hard copy for $24.00!
They have several books available and all their books are very well explained, easy to read, and have FANTASTIC detailed graphic illustrations.
Here is the link to a book called PIC Microcontrollers:
http://www.mikroe.com/eng/categories/vi ... lications/
Here is the link to all the books they have available and several are free to read online. A wealth of knowledge at your finger tips!
http://www.mikroe.com/eng/categories/vi ... lications/
Stacy
Any time you deviate from sequential consistency, you increase the complexity of the problem by orders of magnitude.
- 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
Thanks for the links!
I was actually looking into using their compiler but it was a bit expensive.
The good thing is that they have alot of resources freely available.
I think I will go and make a new forum dedicated to Basic programming.
I will post in there my findings and little tips and tricks to the new language.
I was actually looking into using their compiler but it was a bit expensive.
The good thing is that they have alot of resources freely available.
I think I will go and make a new forum dedicated to Basic programming.
I will post in there my findings and little tips and tricks to the new language.
Re: Moving onto greener pastures!
Without speed and memory penalties, you can advance a lot by using macros, including to make program structures like you would find in higher-level languages (although a lot of BASICs don't even have much in the way of program structures). I have an article and code for doing this in 6502 assembly at http://wilsonminesco.com/StructureMacros/index.html which I will be adding to and then do a similar thing for PIC16 assembly [Edit: done] since, after doing a lot of PIC projects for products we've sold, I'm just now finally doing the first one with the program-structure macros and I want to make sure they all work right before posting code. I have gone as much as two to three pages in the application with no labels, because the structures take care of it. The indentation and somewhat English-like code make it quite clear what you're doing, unlike regular assembly. No spaghetti code. You can have for example lots of variations of IF...ELSE...ENDIF, BEGIN...WHILE...REPEAT, FOR...NEXT, CASE statements, etc., and nest the structures.I really have hit a wall with assembly so I would like to see if I can make bigger and better things with a language that can help me achieve that.
Last edited by Garth on Mon Feb 04, 2013 6:10 pm, edited 1 time in total.
http://WilsonMinesCo.com/ lots of 6502 resources
- 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: Moving onto greener pastures!
After leaving Assembly for Basic and C I have since discovered ways that I could have done in ASM what I wanted without to much difficulty. At the time though I had no idea!
Who is online
Users browsing this forum: No registered users and 3 guests