I'm quite excited to be venturing into basic programming. I have been working with assembly language since 2007 and feel it is time to learn another language.
Basic is a higher level language than assembly and as such, it makes it easier to achieve a set task. Given that I have two kids now, I really am finding it hard to get time to work on my projects - I figure if I can build a project and base it around assembly language, then I shouldn't have to spend so much time on it.
Why is it easier you ask?
There are loads and loads of include files out there that you can freely download. These files have been written by other basic programmers who kindly release them for all to use.
So lets say I wanted to use one of those 16x2 lcd displays (16 characters x 2 lines) and I wanted to write "Hello" on the display.
The assembly code for such a task would be:
Code: Select all
; Myke Predko
; 99.03.13
;
LIST P=16C84, R=DEC ; 16C84 Runs at 4 MHz
errorlevel 0,-305
INCLUDE "p16c84.inc"
; Register Usage
CBLOCK 0x00C ; Start Registers at End of the Values
Dlay ; 8 Bit Delay Variable
Temp ; Temporary Value Used When Sending Out Data
NOTemp ; Temporary Value to "NybbleOutput"
ENDC
; Define Inforation
#DEFINE Data PORTA,0
#DEFINE Clock PORTA, 1
; Macros
ClockStrobe MACRO ; Strobe the Data Bit
bsf Clock
bcf Clock
ENDM
EStrobe MACRO ; Strobe the "E" Bit
bsf Data
bcf Data
ENDM
PAGE
__CONFIG _CP_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF
; Note that the WatchDog Timer is OFF
; Demo Code, Loop Forever Toggling PA0 (Flashing the LED)
org 0
clrf PORTA
movlw 0x01C ; Enable PA0 & PA1 for Output
bsf STATUS, RP0
movwf TRISA ^ 0x080
bcf STATUS, RP0
call Dlay5 ; Wait 20 msecs before Reset
call Dlay5
call Dlay5
call Dlay5
bcf STATUS, C ; Clear Carry (Instruction Out)
movlw 0x03 ; Reset Command
call NybbleOut ; Send the Nybble
call Dlay5 ; Wait 5 msecs before Sending Again
EStrobe
call Dlay160 ; Wait 160 usecs before Sending the Third Time
EStrobe
call Dlay160 ; Wait 160 usecs before Sending the Third Time
bcf STATUS, C
movlw 0x02 ; Set 4 Bit Mode
call NybbleOut
call Dlay160
movlw 0x028 ; Note that it is a 2 Line Display
call SendINS
movlw 0x008 ; Turn off the Display
call SendINS
movlw 0x001 ; Clear the Display RAM
call SendINS
call Dlay5 ; Note, Can take up to 4.1 msecs
movlw 0x006 ; Enable Cursor Move Direction
call SendINS
movlw 0x00C ; Turn the LCD Back On
call SendINS
clrf FSR ; Output the Message
OutLoop
movf FSR, w ; Get the Offset to Output
incf FSR
call Message
iorlw 0 ; At the End of the Message?
btfsc STATUS, Z
goto Loop ; Yes - Equal to Zero
call SendCHAR ; Output the ASCII Character
goto OutLoop
Loop ; Loop Forever when Done
goto Loop
; Subroutines
Message ; Message to Output
addwf PCL ; Output the Characters
dt "Hello", 0
SendCHAR ; Send the Character to the LCD
movwf Temp ; Save the Temporary Value
swapf Temp, w ; Send the High Nybble
bsf STATUS, C ; RS = 1
call NybbleOut
movf Temp, w ; Send the Low Nybble
bsf STATUS, C
call NybbleOut
return
SendINS ; Send the Instruction to the LCD
movwf Temp ; Save the Temporary Value
swapf Temp, w ; Send the High Nybble
bcf STATUS, C ; RS = 0
call NybbleOut
movf Temp, w ; Send the Low Nybble
bcf STATUS, C
call NybbleOut
return
NybbleOut ; Send a Nybble to the LCD
movwf NOTemp ; Save the Nybble to Shift Out
swapf NOTemp ; Setup to Output to the High Part of the Byte
movlw 6 ; Clear the Shift Register
movwf Dlay
NOLoop1
ClockStrobe
decfsz Dlay
goto NOLoop1
bsf Data ; Put out the Gate Bit
ClockStrobe
bcf Data ; Put out the RS Bit
rlf PORTA
ClockStrobe
movlw 4 ; Now, Shift out the Data
movwf Dlay
NOLoop2
rlf NOTemp ; Shift Through the Nybble to Output
bcf Data ; Clear the Data Bit (which is the Clock)
rlf PORTA ; Shift the Carry into the Shift Register
ClockStrobe
decfsz Dlay
goto NOLoop2
EStrobe ; Strobe out the LCD Data
return
Dlay160 ; Delay 160 usecs
movlw 256 - ( 160 / 4 ) ; Loop Until Carry Set
addlw 1
btfss STATUS, C
goto $-2
return
Dlay5 ; Delay 5 msecs
movlw 4 ; Set up the Delay
movwf Dlay
movlw 256 - 0x0E8
addlw 1
btfsc STATUS, Z
decfsz Dlay
goto $-3
return
end
Code: Select all
Include "LCD.bas"
Code: Select all
LCD.WriteAt(1,1,"Hello")
I am finding ALOT of useful information at http://www.digital-diy.com
This is another guy from Australia and knows alot about all sorts of programming languages. I was actually also in the Airforce with him a while back.
The program I am using to code is named SWORDFISH
You can download a free version, the only limit is that you can only have a maximum of 200 variables which really is ALOT of variables. None of my projects have used that much.
You can download swordfish from this link:
http://www.sfcompiler.co.uk/downloads/SwordfishSE.exe
You can also download the reference manual here (very handy!)
http://www.sfcompiler.co.uk/downloads/SFManual.pdf
Well that is all for now!