Code:
'##########################################################
'# #
'# SnugTerm V.1 #
'# serial terminal #
'# #
'# by - snug11@hotmail.com #
'# http://www.pixelklecks.de #
'# Bremen, 23.02.2007 #
'# #
'# Language : Bascom AVR #
'# Hardware : Atmega8/16Mhz, Max232, 20x4 HD44780 #
'# (using a "snugboard" for very easy handling) #
'# #
'# thx for the users of https://www.roboternetz.de #
'# #
'# distribution is free, #
'# but only allowed with this little header ! #
'# #
'##########################################################
$regfile = "m8def.dat"
$crystal = 16000000
$baud = 19200
Config Lcdpin = Pin , Rs = Portb.0 , E = Portb.1 , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5
Config Lcd = 20 * 4
Initlcd
Cursor Off
Cls
Config Portd = Output 'LED o.Ä. an Port D
Config Portc = Input 'Eingänge an Port C
Portc = &B11111111 'Pullups an PortC ein
Print "connected module found !"
Print ""
Locate 1 , 1
Lcd " SnugTerm V1.0 "
Locate 2 , 1
Lcd " by "
Locate 4 , 1
Lcd " snug11@hotmail.com "
Wait 1
Print "SnugTerm V1.0"
Print "by : snug11@hotmail.com"
Print ""
Print ""
Print "Examples :"
Print ""
Print "to write a text in row 2 of display, send : ' z2=that is a test '"
Print "to clear all rows, send : ' cls'"
Print ""
Print "to set led2 on/off, send : ' l2=1 / l2=0 '"
Print "to set all led, send : ' la=1 / la=0 '"
Print ""
Print "to ask for installed components, send : ' cfg '"
Print ""
Print "pushing ever a switch will get : tx=1"
Print ""
Print ""
Print "...now waiting for input !"
Print ""
Config Timer1 = Timer , Prescale = 64 'Interrupt wird erzeugt, springt 10x pro Sekunde nach Sub "Tastenabfrage"
On Timer1 Tastenabfrage
Const Timervorgabe = 57203
Enable Timer1
Enable Interrupts
Dim I As String * 23 'maximal Länge Tastatureingabe (fuer LCD 20x4)
Dim T As String * 20 'Länge des Textstrings
Dim B As String * 3 'ersten 3 Zeichen für Befehl
Dim O As String * 1 '4. Zeichen - Wert = 1 oder 0
Dim Taster As Byte
Dim Led As Byte
Dim Zeilen As Byte
Dim Zeichen As Byte
Taster = 6 'Anzahl der angeschlossenen Taster
Led = 2 'Anzahl der angeschlossenen LED
Zeilen = 4 'Anzahl Displayzeilen
Zeichen = 20 'Anzahl der Displayzeichen
Main:
Do
Input , I 'max 23 zeichen einlesen
B = Left(i , 3) 'ersten drei zeichen des StringI in Variable B schreiben
T = Mid(i , 4 , 20) 'ab dritten Zeichen alles in Variable T schreiben
O = Mid(i , 4 , 1) 'Abfrage ob viertes Zeichen eine 1 oder 0 für LED`s
If B = "z1=" Then Goto Zeile1 'wenn ersten drei zeichen z1=,z2= oder l1=..., dann springe entsprechend
If B = "z2=" Then Goto Zeile2
If B = "z3=" Then Goto Zeile3
If B = "z4=" Then Goto Zeile4
If B = "cls" Then Goto Cls
If B = "l1=" Then Goto Led1
If B = "l2=" Then Goto Led2
If B = "la=" Then Goto Lall
If B = "cfg" Then Goto Config 'Abfrage der angeschlossenen Hardware
'Locate 3 , 1
'Lcd I
'Locate 4 , 1
'Lcd B
I = ""
Loop
Zeile1:
Locate 1 , 1
Lcd " "
Locate 1 , 1 'springe in erste Postition der Zeile 1
Lcd T 'gebe alles ab drittem zeichen der Eingabe aus
Goto Main 'und wieder zur Hauptroutine
Zeile2:
Locate 2 , 1
Lcd " "
Locate 2 , 1
Lcd T
Goto Main
Zeile3:
Locate 3 , 1
Lcd " "
Locate 3 , 1
Lcd T
Goto Main
Zeile4:
Locate 4 , 1
Lcd " "
Locate 4 , 1
Lcd T
Goto Main
Cls:
Cls
Goto Main
Led1:
If O = "1" Then Portd.2 = 1 'bei l1=1 schaltet sich LED1 ein
If O = "0" Then Portd.2 = 0 'bei l1=0 schaltet sich LED1 aus
Goto Main
Led2:
If O = "1" Then Portd.3 = 1
If O = "0" Then Portd.3 = 0
Goto Main
Lall:
If O = "0" Then 'bei Eingabe "la=1" gehen alle LED an
Portd.2 = 0
Portd.3 = 0
End If
If O = "1" Then 'bei Eingabe "la=0" gehen alle LED aus
Portd.2 = 1
Portd.3 = 1
End If
Goto Main
'Die Abfrage 'cfg" listet Konfiguration auf
Config:
Print "#t=" ; Taster ; ",l=" ; Led ; ",r=" ; Zeilen ; ",c=" ; Zeichen ; "#"
Goto Main
Tastenabfrage:
Locate 1 , 1
If Pinc.0 = 0 Then Print "T1=1" 'gib bei Tastendruck über RS232 "T1=1" aus
If Pinc.1 = 0 Then Print "T2=1"
If Pinc.2 = 0 Then Print "T3=1"
If Pinc.3 = 0 Then Print "T4=1"
If Pinc.4 = 0 Then Print "T5=1"
If Pinc.5 = 0 Then Print "T6=1"
Return
Lesezeichen