P. 1
Introduction to Practical Electronics Microcontrollers and Software Design

Introduction to Practical Electronics Microcontrollers and Software Design

|Views: 507|Likes:
Published by Stefanvnv
An Introduction to
Practical Electronics,
Microcontrollers and
Software Design
An Introduction to
Practical Electronics,
Microcontrollers and
Software Design

More info:

Published by: Stefanvnv on Feb 22, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/19/2013

pdf

text

original

1. Copy the following code into BASCOM
2. Compare the datasheet for the LCD with the characters that actually appear on your
LCD.
3. Write the code for the decrementcode subroutine

'------------------------------------------------------------------
' 1. Title Block
' Author: B.Collis
' Date: 1 June 2005
' File Name: LCDcharactersV1.bas
'------------------------------------------------------------------
' 2. Program Description:
' everytime btn is pressed the character on the lcd changes
' highlights the use of the ASCII code
' 3. Hardware Features:
' LEDS
' 5 switches
' LCD
' 4. Program Features
' do-loop to keep program going forever
' debounce to test switches
' if-then-endif to test variables
'------------------------------------------------------------------
' 5. Compiler Directives (these tell Bascom things about our hardware)
$crystal = 8000000 'the speed of the micro
$regfile = "m8535.dat" 'our micro, the ATMEGA8535-16PI
'------------------------------------------------------------------
' 6. Hardware Setups
' setup direction of all ports
Config Porta = Output 'LEDs on portA
Config Portb = Output 'LEDs on portB
Config Portc = Output 'LEDs on portC
Config Portd = Output 'LEDs on portD
'config inputs
Config Pind.2 = Input 'switch A
Config Pind.3 = Input 'switch B
Config Pind.6 = Input 'switch C
Config Pinb.1 = Input 'switch D
Config Pinb.0 = Input 'switch E
'LCD
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E =
Portc.1 , Rs = Portc.0
Config Lcd = 20 * 4
' 7. Hardware Aliases
Sw_a Alias Pinb.0
Sw_b Alias Pinb.1
Sw_c Alias Pind.2
Sw_d Alias Pind.3
Sw_e Alias Pind.6

' 8. initialise ports so hardware starts correctly
Porta = &B11111100 'turns off LEDs ignores ADC inputs
Portb = &B11111100 'turns off LEDs ignores switches

345

Portc = &B11111111 'turns off LEDs
Portd = &B10110011 'turns off LEDs ignores switches
Cls 'clear lcd screen
'------------------------------------------------------------------
' 9. Declare Constants
'------------------------------------------------------------------
' 10. Declare Variables
Dim Code As Byte
Dim State As Byte
' 11. Initialise Variables
Code = 0
State = 0
'------------------------------------------------------------------
' 12. Program starts here
Do

Debounce Sw_a , 0 , Swa_press , Sub
Debounce Sw_b , 0 , Swb_press , Sub
If State = 0 Then Gosub Intro
If State = 1 Then Gosub Increasecode
If State = 2 Then Gosub Decreasecode
If State = 4 Then Gosub Waiting

Loop
End 'end program

'------------------------------------------------------------------
' 13. Subroutines
Intro:

Lcd "ASCII codes"
Lowerline
Lcd "btn A incrs code"

Return

Waiting:
'

do nothing

Return

Increasecode:

If Code < 255 Then 'max value is 255
Incr Code

Else

Code = 0 'if > 255 reset to 0

End If
Cls
Lcd Code : Lcd " " : Lcd Chr(code)
State = 4

Return

346

Decreasecode:
'write your code here

Return

Swa_press:
State = 1
Return

Swb_press:
State = 2
Return

347

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->