no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | atmel:relaycontrollersource2 [2009/11/27 17:53] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <code vb> | ||
+ | ' | ||
+ | '* Relay controller | ||
+ | '* Language: | ||
+ | '* Date: 2008.Oct.22 | ||
+ | '* Version: | ||
+ | ' | ||
+ | $regfile = " | ||
+ | $crystal = 8000000 | ||
+ | |||
+ | $baud = 9600 | ||
+ | |||
+ | Declare Sub Avr_os() | ||
+ | Declare Sub Initialize() | ||
+ | Declare Sub Printprompt() | ||
+ | Declare Sub Docommand() | ||
+ | Declare Sub Getinput(byval Pbbyte As Byte) | ||
+ | Declare Sub Status() | ||
+ | Declare Sub Poweron(byval Relay As Byte) | ||
+ | Declare Sub Poweroff(byval Relay As Byte) | ||
+ | Declare Sub Lcddisplay(pos As Byte) | ||
+ | |||
+ | ' If you change this number you must setup the PORT mappings | ||
+ | ' in the initalize section. | ||
+ | Const Relays = 4 | ||
+ | |||
+ | Const Cpcinput_len = 30 ' | ||
+ | |||
+ | Dim Rport(relays) As Byte | ||
+ | Dim Gbinp As Byte ' | ||
+ | Dim Gspcinput As String * Cpcinput_len | ||
+ | Dim Gspcinp(cpcinput_len) As Byte At Gspcinput Overlay | ||
+ | Dim Gbpcinputpointer As Byte ' string-pointer during user-input | ||
+ | Dim Command As String * 5 | ||
+ | |||
+ | Dim P1 As Byte , P2 As Byte | ||
+ | Dim I As Byte | ||
+ | Dim J As Byte | ||
+ | |||
+ | Config Portb = Output | ||
+ | Open " | ||
+ | ' Serial communication to LCD is via port b.6 | ||
+ | Open " | ||
+ | |||
+ | Enable Interrupts | ||
+ | |||
+ | 'LCD reset | ||
+ | Reset Portb.5 | ||
+ | Waitms 400 | ||
+ | Set Portb.5 | ||
+ | Waitms 400 | ||
+ | |||
+ | Initialize | ||
+ | Avr_os | ||
+ | End | ||
+ | |||
+ | |||
+ | Sub Initialize | ||
+ | ' Setup Port to relay mapping | ||
+ | Rport(1) = 2 : Rport(2) = 3 : Rport(3) = 4 : Rport(4) = 7 | ||
+ | ' Set all Relays OFF | ||
+ | For I = 1 To Relays | ||
+ | Set Portb.rport(i) | ||
+ | Next I | ||
+ | End Sub | ||
+ | |||
+ | |||
+ | Sub Avr_os | ||
+ | Print #1 , "" | ||
+ | Print #1 , " | ||
+ | Print #2 , " | ||
+ | Printprompt | ||
+ | Do | ||
+ | Gbinp = Inkey(# | ||
+ | If Gbinp <> 0 Then ' something typed in? | ||
+ | Getinput Gbinp ' give input to interpreter | ||
+ | End If | ||
+ | Loop ' do forever | ||
+ | End Sub | ||
+ | |||
+ | Sub Printprompt | ||
+ | Gbpcinputpointer = 1 | ||
+ | Gspcinput = "" | ||
+ | Print #1 , ">"; | ||
+ | End Sub | ||
+ | |||
+ | |||
+ | Sub Getinput(pbbyte As Byte) | ||
+ | ' | ||
+ | | ||
+ | Case & | ||
+ | Case & | ||
+ | Print #1 , Chr(& | ||
+ | | ||
+ | | ||
+ | Case & | ||
+ | If Gbpcinputpointer > 1 Then | ||
+ | Print #1 , Chr(& | ||
+ | Decr Gbpcinputpointer | ||
+ | End If | ||
+ | Case Else ' | ||
+ | If Gbpcinputpointer <= Cpcinput_len Then | ||
+ | Mid(gspcinput , Gbpcinputpointer , 1) = Pbbyte | ||
+ | Incr Gbpcinputpointer | ||
+ | Mid(gspcinput , Gbpcinputpointer , 1) = & | ||
+ | Print #1 , Chr(pbbyte); | ||
+ | End If | ||
+ | End Select | ||
+ | End Sub | ||
+ | |||
+ | Sub Docommand | ||
+ | Gspcinput = Ucase(gspcinput) | ||
+ | |||
+ | Select Case Gspcinput | ||
+ | Case " | ||
+ | Case Else | ||
+ | I = Instr(gspcinput , " ") | ||
+ | Decr I | ||
+ | Command = Mid(gspcinput , 1 , I) | ||
+ | I = I + 2 | ||
+ | J = Gspcinp(i) - 48 | ||
+ | |||
+ | ' | ||
+ | | ||
+ | Case " | ||
+ | Case " | ||
+ | Case " | ||
+ | Case Else | ||
+ | Print #1 , " | ||
+ | End Select | ||
+ | End Select | ||
+ | |||
+ | End Sub | ||
+ | |||
+ | ' | ||
+ | |||
+ | Sub Lcddisplay(pos As Byte) | ||
+ | Print #2 , Mid(gspcinput , Pos) | ||
+ | End Sub | ||
+ | |||
+ | Sub Poweron(relay As Byte) | ||
+ | If Relay <= Relays Then | ||
+ | Reset Portb.rport(relay) | ||
+ | End If | ||
+ | End Sub | ||
+ | |||
+ | Sub Poweroff(relay As Byte) | ||
+ | If Relay <= Relays Then | ||
+ | Set Portb.rport(relay) | ||
+ | End If | ||
+ | End Sub | ||
+ | |||
+ | Sub Status | ||
+ | For I = 1 To Relays | ||
+ | Print #1 , " | ||
+ | If Portb.rport(i) = 1 Then | ||
+ | Print " | ||
+ | Else | ||
+ | Print " | ||
+ | End If | ||
+ | Next I | ||
+ | End Sub | ||
+ | </ | ||
+ | {{tag> |