BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sun Jul 22, 2018 9:51 am

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Demo Code for Nano18 UPDATED 081210
PostPosted: Tue Aug 18, 2009 9:14 pm 
Offline
Master

Joined: Mon Aug 18, 2008 1:26 am
Posts: 799
Location: CA bay Area
A quick test of this in Studio_35 shows that this is in need of an update due to syntax changes in the compiler. That is, it won't compile! Even this produces two messages about page boundaries. Not to worry, it programs and works OK! This has a few bells and whistles added from the original version, read the header for program operation.

As always, well commented to help you follow the logic!
[code; 8/12/10 - Nano18 Demo Code, done with Nano Development Board
; Wiring: (Wired with power OFF!, to be run with Nano and LCD installed, speaker is optional)
; P0 to P7 - LCD connector
; P8 - POT (ADC readings)
; P9 - LED1
; P10 - LED2
; P11, P12 - SPK1 (speaker)(don't run this without an electrolytic
; capacitor, 1 - 10 uF, between outputs P11-P12 and SPK1 connection for isolation)
; P13 to SW2
; This program outputs the values of a loop count (1 to 100) and the ADC readings
; (0 to 1023) from the pot at R13, on both the LCD and serial terminal.
; The loop count also determines which LED blinks when above and below 50. And it determines
; how long the tone is played on the speaker, where the loop count is multiplied
; times 1000.
; When the ADC readings go above 512 (half way point) the LCD reading switches from
; reporting the loop value to the ADC value, and both LEDs light together solidly,
; as opposed to the blinking during loop value displays.
; As the speaker output value increases (looper*1000), everything runs a little slower.
; Pressing SW2 causes LEDs to blink.
; We also demonstrate using the EEPROM by storing an incrementing value, "Btemp",
; which is used to report how many times you have started the program from power-ON
; and after every reset.
; You also see a Reset Interrupt in action, ONMOR, "On Master Master Reset".
; Look for "RESET!!" at evry reset-forced restart, as in clicking
; on "Connect" in the terminal window, or pressing the Reset switch. You will NOT see this
; when powering up the board. Every forced-restart causes the program to jump to _onreset.

;;; variable assignments ;;;
char var byte(10)
BTemp var byte
Wtemp var word
looper var byte
Btemp = 0 ; initialize Btemp to "0"

pause 500 ; give LCD time to initialize internally
onmor _onreset

;;; initializations ;;;
writedm 0, [Btemp] ; write Btemp to EEPROM

_startup
; get the Btemp value, increment and store in EEPROM
readdm 0, [Btemp]
Btemp = Btemp + 1
writedm 0, [Btemp]
; Entering your name for display:
; Change the array "char" below to your name. Only 9 characters are actually displayed.
char = REP " "\10 ; fill array "char" with spaces
char = "yourname" ; you need to keep the quotes ("")
lcdinit p0\p1\p7\p6\p5\p4 ; init LCD
high p3 ; turn on LCD backlight
pause 300 ; give LCD time to initialize
; start with both LEDs off
low p9 ; controls LED1
low p10 ; controls LED2

; LCD reports user's name
lcdwrite p0\p1\p7\p6\p5\p4,[CLEARLCD,HOMELCD,SCR,TWOLINE,"Hello ", str char\9]
serout s_out, i9600, [0] ; clear the terminal screen
MAIN
; exercise terminal display
serout s_out, i9600, [0] ; clear the terminal screen
serout s_out, i9600, ["Hello ", str char\9, "! This is Start#: ", dec Btemp,13]
pause 1000 ; a one second pause to view message
; This says, "Hello" plus your name up to 9 characters if you entered it above
lcdwrite p0\p1\p7\p6\p5\p4,[CLEARLCD,HOMELCD,SCR,TWOLINE,"Hello ", str char\9]

for looper = 20 to 80 ; produce count in displays

; the followig reads the voltage from the pot at R13 and makes decisions based on this value
adin p8, Wtemp ; get ADC reading from pot at R13
if Wtemp > 512 then ; two lighted LEDs indicate pot reading above 512
high p9
high p10
gosub _pot ; LCD now reports ADC readings instead of looper value
goto _skip ; bypass the next comparison
endif

; the following blinks LED1 when looper less than 50, LED2 if higher than 50
if looper < 50 then
low p10 ; LED2 OFF
toggle p9 ; LED1 on/off
else ; when looper greater than 50
low p9 ; shut off LED1
toggle p10 ; LED2 on/off
endif

; report values
lcdwrite p0\p1\p7\p6\p5\p4,[scrram+40, "Looper is ", dec looper\3, " "]
_skip ; bypass lcdwrite above

; find if SW2 has been pressed
IF IN13 = 0 then ; if yes, then make LEDs blink
gosub _switch_down
endif

serout s_out, i9600, ["looper is now ", dec3 looper, " , ADC is ", dec Wtemp, 13] ; display looper value, limit to 3 characters

; execise speaker with tone consistently running higher, longer
sound p11,[looper * 10\looper * 40]
sound p12,[looper * 10\looper * 30]

next ; looper
goto main ; repeat

_pot ; routine for reporting ADC values to LCD if ADC reading GT 512 ; GT = Greater Than
high p3 ; make sure backlight is on
lcdwrite p0\p1\p7\p6\p5\p4,[scrram+40, "ADC reads ", dec4 Wtemp\4] ; reports ADC value, Wtemp
return

_switch_down ; makes LEDs blink when SW2 is down
toggle P9
toggle P10
return

_onreset
serout s_out, i9600, [0] ; clear the terminal screen
serout s_out, i9600, ["RESET!!",13] ; exercise terminal display
pause 500 ; half a second pause to view message
serout s_out, i9600, [0] ; clear the terminal screen
goto _startup[/code]

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO