Pada kesempatan yang berbahagia kali ini saya akan menjelaskan mengenai project baru saya yaitu mengenai BASIC STAMP, ada banyak tipe dari mikrokontroller ini, pada tutorial kali ini saya menggunakan Basic Stamp BS2P40 buatan parallax. Kelebihan dari mikrokontroller Basic Stamp ini dibanding mikrokontroller ATMega yaitu kecepatan clocknya. Basic Stamp bisa memiliki kecepatan Clock hingga 20MHz. sehingga untuk pemprosesan sinyal bisa diandalkan. Namun kekurangan mikrokontroller ini yaitu tidak adanya chip ADC sehingga menggunakan chip ADC ekseternal. Pada tutorial kali ini dibahas mengenai bagaimana cara mengakses LED I/O , LCD 16x2 dan Sensor Jarak PING))). berikut adalah skema dan programnya.
a. Basic Stamp BS2P40
b. LED
c. LCD 16x2
d. Sensor Jarak PING)))
e. ADC 8 Bit ( IC ADC0831 )
f. Program I/O Led
' {$STAMP BS2p} ‘A directive to the Stamp that you are Using the Basic Stamp 2
' {$PBASIC 2.5}Top: 'This is a label that allows you TO refer TO this label later ON in the ‘program.
HIGH 0 'Set PIN one TO logic HIGH 5 volts
PAUSE 1500 'PAUSE the program FOR 1 & 1/2 seconds
LOW 0 'Set the PIN 0 TO LOW OR logic LOW 0 volts.
PAUSE 1500 'PAUSE program FOR 1 & 1/2 seconds
GOTO Top 'RETURN TO the label “Top:”
g. Program LCD 16x2 + Sensor Jarak PING )))
' This program demonstrates initialization and printing on a 2 x 16
' character LCD display. The set of "LCD constants", below, are provided
' as pre-defined and useful LCD commands, though not all are actually
' used in this program.
' {$STAMP BS2p}
' {$PBASIC 2.5}
#IF ($STAMP < BS2P) #THEN
#ERROR "Program requires BS2p, BS2pe or BS2px."
#ENDIF
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
Lcd PIN 0
LcdCls CON $01 ' clear the LCD
LcdHome CON $02 ' move cursor home
LcdCrsrL CON $10 ' move cursor left
LcdCrsrR CON $14 ' move cursor right
LcdDispL CON $18 ' shift chars left
LcdDispR CON $1C ' shift chars right
LcdDDRam CON $80 ' Display Data RAM
LcdCGRam CON $40 ' Character Generator RAM
LcdLine1 CON $80 ' DDRAM address of line 1
LcdLine2 CON $C0 ' DDRAM address of line 2
Init_LCD:
PAUSE 1000 ' allow LCD to self-initialize first
LCDCMD Lcd, 110000 ' send wakeup sequence to LCD
PAUSE 5 ' pause required by LCD specs
LCDCMD Lcd, 110000
PAUSE 0 ' pause required by LCD specs
LCDCMD Lcd, 110000
PAUSE 0 ' pause required by LCD specs
LCDCMD Lcd, 100000 ' set data bus to 4-bit mode
LCDCMD Lcd, 101000 ' set to 2-line mode with 5x8 font
LCDCMD Lcd, 001100 ' display on without cursor
LCDCMD Lcd, 000110 ' auto-increment cursor
Main:
LCDCMD Lcd, LcdCls
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
' DEBUG HOME, DEC3 cmDistance, " cm"
' DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
'LCDOUT Lcd, LcdCls, [DEC3 cmDistance]
LCDOUT Lcd, LcdLine1, ["Jarak = "]
LCDOUT Lcd, LcdLine1 + 8 , [DEC3 inDistance]
LCDOUT Lcd, LcdLine1 + 11 ,[" cm"]
LCDOUT Lcd, LcdLine2, ["Berat = "]
PAUSE 200
' LCDCMD Lcd, LcdCls
' PAUSE 500
LOOP
END
h. Program ADC0831 (ADC) + PING))) + LCD
' LCDINIT.bsp
' This program demonstrates initialization and printing on a 2 x 16
' character LCD display. The set of "LCD constants", below, are provided
' as pre-defined and useful LCD commands, though not all are actually
' used in this program.
' {$STAMP BS2p}
' {$PBASIC 2.5}
#IF ($STAMP < BS2P) #THEN
#ERROR "Program requires BS2p, BS2pe or BS2px."
#ENDIF
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
Lcd PIN 0
CS PIN 14 ' chip select
AData PIN 12 ' data pin
Clk PIN 13 ' clock pin
Berat VAR Byte ' ADC result
LcdCls CON $01 ' clear the LCD
LcdHome CON $02 ' move cursor home
LcdCrsrL CON $10 ' move cursor left
LcdCrsrR CON $14 ' move cursor right
LcdDispL CON $18 ' shift chars left
LcdDispR CON $1C ' shift chars right
LcdDDRam CON $80 ' Display Data RAM
LcdCGRam CON $40 ' Character Generator RAM
LcdLine1 CON $80 ' DDRAM address of line 1
LcdLine2 CON $C0 ' DDRAM address of line 2
Setup:
HIGH CS ' deselect ADC
Init_LCD:
PAUSE 1000 ' allow LCD to self-initialize first
LCDCMD Lcd, 110000 ' send wakeup sequence to LCD
PAUSE 5 ' pause required by LCD specs
LCDCMD Lcd, 110000
PAUSE 0 ' pause required by LCD specs
LCDCMD Lcd, 110000
PAUSE 0 ' pause required by LCD specs
LCDCMD Lcd, 100000 ' set data bus to 4-bit mode
LCDCMD Lcd, 101000 ' set to 2-line mode with 5x8 font
LCDCMD Lcd, 001100 ' display on without cursor
LCDCMD Lcd, 000110 ' auto-increment cursor
Main:
LCDCMD Lcd, LcdCls
DO
LOW CS ' activate the ADC0831
SHIFTIN AData, Clk, MSBPOST, [Berat\9] ' shift in the data
HIGH CS
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
' DEBUG HOME, DEC3 cmDistance, " cm"
' DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
'LCDOUT Lcd, LcdCls, [DEC3 cmDistance]
LCDOUT Lcd, LcdLine1, ["Jarak = "]
LCDOUT Lcd, LcdLine1 + 8 , [DEC3 inDistance]
LCDOUT Lcd, LcdLine1 + 11 ,[" cm"]
LCDOUT Lcd, LcdLine2, ["Berat = "]
LCDOUT Lcd, LcdLine2 + 8 , [DEC3 Berat ]
LCDOUT Lcd, LcdLine2 + 11, [" kg"]
PAUSE 200
' LCDCMD Lcd, LcdCls
LOOP
END
i. VIDEO HASILNYA
No comments:
Post a Comment