No worries--I'm learning right now tooI started learning ASM quite a while back, but I quickly turned to C. The tutorials at **broken link removed** helped me a lot, and they may help you too. I posted a link to the tutorial with data tables in my edit of post #38
thanks for the helpi didn't see the link befor i posted my last post but i'm going to take a look at the page ASAP .
Haha, no problem. Your post came over while I was putting in the edit. Good luck! I hope it helps
ser_out:
movwf sendreg ;save copy of number
movlw 0x08 ; load count for 8 bits
movwf count
testbit:
bcf GPIO,0 ; clear bit (default)
btfsc sendreg,7 ;7 test upper bit
bsf GPIO,0 ; set bit
clock:
bcf GPIO,2
nop ; send clock pulse
bsf GPIO,2
roflt:
rlf sendreg,f ; shift left
decfsz count,f ; decrement bit
goto testbit ; next bit
bcf GPIO,2
nop ; extra clock pulse if
bsf GPIO,2 ; clocks are tied
Hi Lurkepus,
I would suggest you go check out Nigel's tutorials as I do think it is the best way to get your feet wet in using assembly. In the LCD tutorial there are the routines for doing just what you need. Also it would be more helpful if you put the full code in not just snippets then we can get the full picture. On a personal note I did start in ASM then found Oshonsoft Basic and I have found that to much easier to use and having the simulator and Eric's external modules does make for one complete learning tool.
Regards Bryan
list p=12f683 ; list directive to define processor
#include <p12F683.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)
;
;*************** cblock Variabler ************************************
cblock 0x20
Temp ;Temp variabel
d1
d2
d3
sendreg
count
endc
;*********************Register oppsett********************************
org 0 ;Flash start adresse 0
Start:
bsf STATUS,RP0 ;Bank 1
movlw 0x47
movwf OSCCON ;4 MHZ oscilator (0x70 = 8 MHZ)
clrf TRISIO ; ALLE I/O porter =output
clrf ANSEL ; Alle I/O porter =digital
bcf STATUS,RP0 ;Bank 0
;********************HOVED PROGRAMM ************************************
Main:
bsf GPIO,1
clrf sendreg
movlw 0x20 ; LCD startup
movwf sendreg
call ser_out
nop
nop
nop
movlw 0x20
movwf sendreg
call ser_out
nop
nop
nop
movlw 0x20
movwf sendreg
call ser_out
nop
nop
nop
movlw 0x28
movwf sendreg
call ser_out
nop
nop
movlw 0xc
movwf sendreg
call ser_out
nop
nop
movlw 0x06
movwf sendreg
call ser_out
nop
nop
movlw 0x01
movwf sendreg
call ser_out
nop
nop
Data_out:
bcf GPIO,1
clrf sendreg
movlw 'a'
movwf sendreg
call ser_out
movlw 'w'
movwf sendreg
call ser_out
movlw 's'
movwf sendreg
call ser_out
movlw 'f'
movwf sendreg
call ser_out
movlw 'G'
movwf sendreg
call ser_out
movlw 'H'
movwf sendreg
call ser_out
goto Main
ser_out:
movwf sendreg ;save copy of number
movlw 0x08 ; load count for 8 bits
movwf count
testbit:
bcf GPIO,0 ; clear bit (default)
btfsc sendreg,7 ;7 test upper bit
bsf GPIO,0 ; set bit
clock:
bcf GPIO,2
nop ; send clock pulse
bsf GPIO,2
roflt:
rlf sendreg,f ; shift left
decfsz count,f ; decrement bit
goto testbit ; next bit
bcf GPIO,2
nop ; extra clock pulse if
bsf GPIO,2 ; clocks are tied
end
btw do you have a link to Nigel's LCD tutorial ??
I had a look at the Oshonsoft Basic only problem is that i don't have any pc running winshit all my comps are using linux Mplab is running under wine and i'm using PicProg to burn the chip ..I did start in ASM then found Oshonsoft Basic and I have found that to much easier to use and having the simulator and Eric's external modules does make for one complete learning tool.
Regards Bryan
;******************************************************************
; *
; Filename: 12F683 595 LCD RB.asm *
; Author: Mike McLaren, K8LH *
; Date: 03-Nov-11 *
; *
; *
; Raj Bhatt's 12F683 + 74HC595 + LCD Circuit Experiment *
; *
; MPLab: 8.80 (tabs = 8) *
; MPAsm: 5.43 *
; *
;******************************************************************
processor PIC12F683
include "P12F683.inc"
list st=off ; suppress LST file symbol table
errorlevel -302 ; suppress bank warning messages
radix dec
__CONFIG _MCLRE_OFF & _WDT_OFF & _INTOSCIO
;
; variables
;
cblock 0x20
work ; low level lcd work variable
delayhi ; DelayCy() work variable
endc
;
; defines
;
#define clk_pin GPIO,1 ; to 74HC595 CLK & LAT pins
#define dat_pin GPIO,5 ; to 74HC595 DAT pin
#define ena_pin GPIO,2 ; to LCD 'E' pin
;******************************************************************
; K8LH DelayCy() subsystem macro generates four instructions *
;******************************************************************
radix dec
clock equ 8 ; 4, 8, 12, 16, 20 (MHz), etc.
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ clock/4*1000 ; cycles/millisecond multiplier
DelayCy macro delay ; 11..327690 cycle range
movlw high((delay-11)/5)+1
movwf delayhi
movlw low ((delay-11)/5)
call uDelay-((delay-11)%5)
endm
;******************************************************************
; reset vector *
;******************************************************************
org 0x0000
v_reset
clrf STATUS ; force bank 0, IRP = 0 |B0
goto init ; |B0
;******************************************************************
; interrupt vector *
;******************************************************************
org 0x0004
v_int
;******************************************************************
; subroutines *
;******************************************************************
PutCMD
clrc ; C = RS = 0 (command) |B0
skpnc ; skip |B0
PutDAT
setc ; C = RS = 1 (data) |B0
movwf work ; save data |B0
call PutNyb ; send hi nybble |B0
swapf work,F ; |B0
call PutNyb ; send lo nybble |B0
DelayCy(40*usecs) ; 40 us inter-char delay |B0
return ; |B0
;
; shift out RS bit, the hi nibble bits, and one extra clock
;
PutNyb
bcf dat_pin ; dat = 0 |B0
skpnc ; RS = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 (strobe clk) |B0
bcf clk_pin ; clk = 0 |B0
b7 bcf dat_pin ; dat = 0 |B0
btfsc work,7 ; b7 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
b6 bcf dat_pin ; dat = 0 |B0
btfsc work,6 ; b6 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
b5 bcf dat_pin ; dat = 0 |B0
btfsc work,5 ; b5 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
b4 bcf dat_pin ; dat = 0 |B0
btfsc work,4 ; b4 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
bsf clk_pin ; clk = 1 (extra clock) |B0
bcf clk_pin ; clk = 0 |B0
bsf ena_pin ; ena = 1 (strobe data) |B0
bcf ena_pin ; ena = 0 |B0
return ; |B0
;******************************************************************
; K8LH DelayCy() 16-bit uDelay (11..327690 cycle) subroutine *
; *
nop ; entry for (delay-11)%5 == 4 |B0
nop ; entry for (delay-11)%5 == 3 |B0
nop ; entry for (delay-11)%5 == 2 |B0
nop ; entry for (delay-11)%5 == 1 |B0
uDelay addlw -1 ; subtract 5 cycle loop time |B0
skpc ; borrow? no, skip, else |B0
decfsz delayhi,F ; done? yes, skip, else |B0
goto uDelay ; do another loop |B0
return ; |B0
;******************************************************************
; main.init *
;******************************************************************
;
; void main() //
; { //
; cmcon0 = 7; // comparator off, digital I/O
; osccon = 0x70; // setup INTOSC for 8-MHz
; while(osccon.HTS == 0); // wait for osc 'stable' flag
; trisio = 0b00001000; // GP3 input, others outputs
; gpio = 0; // clear all output latches
;
init
movlw 7 ; |B0
movwf CMCON0 ; comparator off, digital I/O |B0
bsf STATUS,RP0 ; bank 1 |B1
clrf ANSEL ; analog ADC off, digital I/O |B1
movlw 0x70 ; |B1
movwf OSCCON ; setup INTOSC = 8-MHz |B1
stable
btfss OSCCON,HTS ; osc stable? yes, skip, else |B1
goto stable ; |B1
movlw b'00001000' ; |B1
movwf TRISIO ; GP3 input, others outputs |B1
bcf STATUS,RP0 ; bank 0 |B0
clrf GPIO ; set all output latches low |B0
;
; //
; // initialize HD44780 display in 4-bit interface mode
; //
; delay_ms(100); // 100 msec LCD 'power up' reset
; PutNyb(0x20); // hi nibble of "4-bit" command
; PutCMD(0x28); // 4-bit, 2-lines, 5x7 font
; PutCMD(0x08); // display, cursor, blink all off
; PutCMD(0x01); // clear display
; delay_us(1530); // required 1.53 msec delay
; PutCMD(0x06); // cursor inc, shift off
; PutCMD(0xC0); // display on, leave cursor off
;
DelayCy(100*msecs) ; 100-msec LCD 'power up' reset |B0
movlw 0x20 ; hi nybble of "4-bit" command |B0
call PutNyb ; set "4-bit interface" mode |B0
movlw 0x28 ; 4-bit, 2-lines, 5x7 font |B0
call PutCMD ; send "function set" command |B0
movlw 0x08 ; display, cursor, blink all off |B0
call PutCMD ; send "display on/off" command |B0
movlw 0x01 ; clear display (1.53-msecs) |B0
call PutCMD ; send "entry mode set" command |B0
DelayCy(1530*usecs) ; 1.53 msec delay for "clear" |B0
movlw 0x06 ; cursor inc, shift off |B0
call PutCMD ; send "entry mode set" command |B0
movlw 0xC0 ; display on, leave cursor off |B0
call PutCMD ; send "display on/off" command |B0
;
movlw 'H' ; print "hello world" |B0
call PutDAT ; send 'H' |B0
movlw 'e' ; |B0
call PutDAT ; send 'e' |B0
movlw 'l' ; |B0
call PutDAT ; send 'l' |B0
movlw 'l' ; |B0
call PutDAT ; send 'l' |B0
movlw 'o' ; |B0
call PutDAT ; send 'o' |B0
movlw ' ' ; |B0
call PutDAT ; send ' ' |B0
movlw 'W' ; |B0
call PutDAT ; send 'W' |B0
movlw 'o' ; |B0
call PutDAT ; send 'o' |B0
movlw 'r' ; |B0
call PutDAT ; send 'r' |B0
movlw 'l' ; |B0
call PutDAT ; send 'l' |B0
movlw 'd' ; |B0
call PutDAT ; send 'd' |B0
loop goto loop ; loop forever |B0
;******************************************************************
end
stable
;btfss OSCCON,HTS ; osc stable? yes, skip, else |B1
;goto stable ; |B1
uDelay ;addlw -1 ; subtract 5 cycle loop time |B0
;skpc ; borrow? no, skip, else |B0
decfsz delayhi,f ; done? yes, skip, else |B0
;******************************************************************
; *
; Filename: 12F683 595 LCD RB.asm *
; Author: Mike McLaren, K8LH *
; Date: 03-Nov-11 revised 16-Nov-11 *
; *
; *
; Raj Bhatt's 12F683 + 74HC595 + LCD Circuit Experiment *
; *
; MPLab: 8.80 (tabs = 8) *
; MPAsm: 5.43 *
; *
;******************************************************************
processor PIC12F683
include "P12F683.inc"
list st=off ; suppress LST file symbol table
errorlevel -302 ; suppress bank warning messages
radix dec
__CONFIG _MCLRE_OFF & _WDT_OFF & _INTOSCIO
;
; variables
;
cblock 0x20
work ; low level lcd work variable
delayhi ; DelayCy() work variable
endc
;
; defines
;
#define clk_pin GPIO,1 ; to 74HC595 CLK & LAT pins
#define dat_pin GPIO,5 ; to 74HC595 DAT pin
#define ena_pin GPIO,2 ; to LCD 'E' pin
;******************************************************************
; K8LH DelayCy() subsystem macro generates four instructions *
;******************************************************************
radix dec
clock equ 8 ; 4, 8, 12, 16, 20 (MHz), etc.
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ clock/4*1000 ; cycles/millisecond multiplier
DelayCy macro delay ; 11..327690 cycle range
movlw high((delay-11)/5)+1
movwf delayhi
movlw low ((delay-11)/5)
call uDelay-((delay-11)%5)
endm
;******************************************************************
; reset vector *
;******************************************************************
org 0x0000
v_reset
clrf STATUS ; force bank 0, IRP = 0 |B0
goto init ; |B0
;******************************************************************
; interrupt vector *
;******************************************************************
org 0x0004
v_int
;******************************************************************
; subroutines *
;******************************************************************
PutCMD
clrc ; C = RS = 0 (command) |B0
skpnc ; skip |B0
PutDAT
setc ; C = RS = 1 (data) |B0
call shiftout ; send hi nybble |B0
swapf work,W ; |B0
PutNyb
call shiftout ; send lo nybble |B0
DelayCy(40*usecs) ; 40 us inter-char delay |B0
return ; |B0
;
; shift out RS bit, the hi nibble bits, and one extra clock
;
shiftout
movwf work ; update work variable |B0
bcf dat_pin ; dat = 0 |B0
skpnc ; RS = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 (strobe clk) |B0
bcf clk_pin ; clk = 0 |B0
b7 bcf dat_pin ; dat = 0 |B0
btfsc work,7 ; b7 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
b6 bcf dat_pin ; dat = 0 |B0
btfsc work,6 ; b6 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
b5 bcf dat_pin ; dat = 0 |B0
btfsc work,5 ; b5 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
b4 bcf dat_pin ; dat = 0 |B0
btfsc work,4 ; b4 = 1? no, skip, else |B0
bsf dat_pin ; dat = 1 |B0
bsf clk_pin ; clk = 1 |B0
bcf clk_pin ; clk = 0 |B0
bsf clk_pin ; clk = 1 (extra clock) |B0
bcf clk_pin ; clk = 0 |B0
bsf ena_pin ; ena = 1 (strobe data) |B0
bcf ena_pin ; ena = 0 |B0
return ; |B0
;******************************************************************
; K8LH DelayCy() 16-bit uDelay (11..327690 cycle) subroutine *
; *
nop ; entry for (delay-11)%5 == 4 |B0
nop ; entry for (delay-11)%5 == 3 |B0
nop ; entry for (delay-11)%5 == 2 |B0
nop ; entry for (delay-11)%5 == 1 |B0
uDelay addlw -1 ; subtract 5 cycle loop time |B0
skpc ; borrow? no, skip, else |B0
decfsz delayhi,F ; done? yes, skip, else |B0
goto uDelay ; do another loop |B0
return ; C = 0 |B0
;******************************************************************
; main.init *
;******************************************************************
;
; void main() //
; { //
; cmcon0 = 7; // comparator off, digital I/O
; osccon = 0x70; // setup INTOSC for 8-MHz
; while(osccon.HTS == 0); // wait for osc 'stable' flag
; trisio = 0b00001000; // GP3 input, others outputs
; gpio = 0; // clear all output latches
;
init
movlw 7 ; |B0
movwf CMCON0 ; comparator off, digital I/O |B0
bsf STATUS,RP0 ; bank 1 |B1
clrf ANSEL ; analog ADC off, digital I/O |B1
movlw 0x70 ; |B1
movwf OSCCON ; setup INTOSC = 8-MHz |B1
stable
btfss OSCCON,HTS ; osc stable? yes, skip, else |B1
goto stable ; |B1
movlw b'00001000' ; |B1
movwf TRISIO ; GP3 input, others outputs |B1
bcf STATUS,RP0 ; bank 0 |B0
clrf GPIO ; set all output latches low |B0
;
; //
; // initialize HD44780 display in 4-bit interface mode
; //
; delay_ms(100); // 100 msec LCD 'power up' reset
; PutNyb(0x20); // hi nibble of "4-bit" command
; PutCMD(0x28); // 4-bit, 2-lines, 5x7 font
; PutCMD(0x08); // display, cursor, blink all off
; PutCMD(0x01); // clear display
; delay_us(1530); // required 1.53 msec delay
; PutCMD(0x06); // cursor inc, shift off
; PutCMD(0xC0); // display on, leave cursor off
;
DelayCy(100*msecs) ; 100-msec LCD 'power up' reset |B0
movlw 0x20 ; hi nybble of "4-bit" command |B0
call PutNyb ; set "4-bit interface" mode |B0
movlw 0x28 ; 4-bit, 2-lines, 5x7 font |B0
call PutCMD ; send "function set" command |B0
movlw 0x08 ; display, cursor, blink all off |B0
call PutCMD ; send "display on/off" command |B0
movlw 0x01 ; clear display (1.53-msecs) |B0
call PutCMD ; send "entry mode set" command |B0
DelayCy(1530*usecs) ; 1.53 msec delay for "clear" |B0
movlw 0x06 ; cursor inc, shift off |B0
call PutCMD ; send "entry mode set" command |B0
movlw 0xC0 ; display on, leave cursor off |B0
call PutCMD ; send "display on/off" command |B0
;
movlw 'H' ; print "hello world" |B0
call PutDAT ; send 'H' |B0
movlw 'e' ; |B0
call PutDAT ; send 'e' |B0
movlw 'l' ; |B0
call PutDAT ; send 'l' |B0
movlw 'l' ; |B0
call PutDAT ; send 'l' |B0
movlw 'o' ; |B0
call PutDAT ; send 'o' |B0
movlw ' ' ; |B0
call PutDAT ; send ' ' |B0
movlw 'W' ; |B0
call PutDAT ; send 'W' |B0
movlw 'o' ; |B0
call PutDAT ; send 'o' |B0
movlw 'r' ; |B0
call PutDAT ; send 'r' |B0
movlw 'l' ; |B0
call PutDAT ; send 'l' |B0
movlw 'd' ; |B0
call PutDAT ; send 'd' |B0
loop goto loop ; loop forever |B0
;******************************************************************
end
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?