Stepper Motor Control With Atmega16
Stepper Motor Control With Atmega16
Home
AVR projects
AVR Interfacing
AVR Tutorials
AVR Tools
Guest Book
Contact Me
Circuit Diagram
Bascom Code
$regfile="m16def.dat"
$crystal=1000000
ConfigKbd=Portb
ConfigLcd=16*2
ConfigLcdpin=Pin,Db4=Portc.4,Db5=Portc.5,Db6=Portc.6,Db7=Portc.7,Rs=
Portc.0,E=Portc.1
ConfigPortd=Output
ConfigPorta=Input
DimAAsByte,BAsByte,KeyAsByte,CAsByte,DAsByte,EAsByte
Cls
CursorOff
B=0
D=1
Q:
Locate1,1
Lcd"Direction:"
Locate2,1
Lcd"Speed:"
Do
'************ReadKeyboard
A=Getkbd()
IfA>15Then
GotoQ
Else
Key=Lookup(a,Dta)
IfKey<=9Then
B=B*10
B=B+Key
'*************Direction
IfD=0ThenLcdB
Waitms270
ElseifKey=10Then
Locate1,11
Lcd"Left"
C=1
D=0
B=0
ElseifKey=11Then
Locate1,11
Lcd"Right"
C=2
D=0
B=0
'****************reset
ElseifKey=13Then
Cls
D=1
B=0
Portd.0=0
Portd.1=0
Waitms50
GotoQ
'****************Enterkey
ElseifKey=14Then
IfD=0Then
SelectCaseC
Case1:GosubR
Case2:GosubT
EndSelect
EndIf
EndIf
EndIf
Wait1
Loop
End
Dta:
Data7,8,9,10,4,5,6,11,1,2,3,12,13,0,14,15
R:
Do
Portd=&B00000001:WaitmsB
Portd=&B00000011:WaitmsB
Portd=&B00000010:WaitmsB
Portd=&B00000110:WaitmsB
Portd=&B00000100:WaitmsB
Portd=&B00001100:WaitmsB
Portd=&B00001000:WaitmsB
Portd=&B00001001:WaitmsB
IfPina.0=1Then
Locate2,1
Lcd"Speed:"
B=0
LcdB;""
Return
EndIf
Loop
T:
Do
Portd=&B00001001:WaitmsB
Portd=&B00001000:WaitmsB
Portd=&B00001100:WaitmsB
Portd=&B00000100:WaitmsB
Portd=&B00000110:WaitmsB
Portd=&B00000010:WaitmsB
Portd=&B00000011:WaitmsB
Portd=&B00000001:WaitmsB
IfPina.0=1Then
Locate2,1
Lcd"Speed:"
B=0
LcdB;""
Return
EndIf
Loop
Download
Bascom code & Proteus simulation file
Similar Posts