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.
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
Once compiled, it also gives me the equivalent assembly code:
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
That's alot of code!