This is a copy of the Demo code for the Atom28 module taken from the Atom lab Board's data sheet. Notice the "(D)" in this thread's title. This is a reminder you must specify the 'D' part in the IDE's part selector, i.e., BasicATOM-28D,
IF you have the 'D' part. If you purchased the module a year or more ago, it's safe to say it isn't a 'D' part. If you select the wrong part, weird things will happen. I know. I selected the wrong part. It did weirrrd things.
Another gotcha is when you copy and paste this from the download PDF page to the programming area of the IDE. Look at the quotes (") around "Hello World". They aren't right. Mine came out as blocks. If you don't change these back to ", then the build or programming fails.
It's well commented, so study the comments some. They will guide wiring later if you don't have the Lab Board itself. You'll notice there are small differences between this and the copy in the data sheet in the LCDWRITE and SEROUT routines. For some reason the original writer created the variable "cnt", then increments it by one every pass through the "main" routine, but never uses it?! So I made it part of the SEROUT.
Code:
;Atom28(D): P16:P19 are on AX0:AX3 of the Lab Board
;Wiring
;P19/AX3 to POT
;P16/AX0 to LED1
;P15 to LED2
;P14 to LED3
;P13 to LED4
;P12 to Button1
;P11 to Button2
;P10 to Buzzer/Speaker
;P9 to Button3
;P8 to Button4
;Setup LCD
lcdinit p0p1p2,outb
lcdwrite p0p1p2,outb,[CLEARLCD,HOMELCD,SCR,TWOLINE,"Hello World"]
;Set pins to known state
low AX0
low p15
low p14
low p13
high p3
;Setup 32 bit variables
temp var long
cnt var long
cnt=0
;Start program main loop
main
;Read analog pin and display value to LCD
cnt=cnt+1
adin AX3,temp
lcdwrite p0p1p2,outb,[SCRRAM+40, "temp: ", dec4 temp4] ; Jump to LCD second line, print temp
;Send analog reading to terminal window set to 9600 baud
serout S_OUT,i9600,["temp: ", dec temp4, " cnt: ", dec cnt, 13]
;Copy state of button switches to LEDs, on/off
out28=in12 ;P28 is AX0
out15=in11
out14=in9
out13=in8
; If button 4 is pressed make sound with buzzer
out3=in8
if(in8)then ; Nice! You don't HAVE to say "If (in8) = 0", it knows by default!
low p10
else
high p10
endif
; Return to main loop
goto main
BasicMicro plans to produce more demo codes like this and release them to the various forums.
Check in often!
kenjj (BasicMicro)