' -----[ Title ]----------------------------------------------------------- ' ' ' File...... morse.BS2 ' Author.... Georg Siotis ' Started... ' Updated... ' BS2-IC Connections: ' ' Pin 0 LCD.11 | ' Pin 1 LCD.12 |-- OutA ' Pin 2 LCD.13 | ' Pin 3 LCD.14 | ' Pin 4 LCD.4 ' Pin 5 LCD.6 ' Pin 6 NC ' Pin 7 NC ' Pin 8 nc ' Pin 9 nc ' Pin 10 nc ' Pin 11 NC ' Pin 12 Morse long ' Pin 13 Morse short ' Pin 14 NC ' Pin 15 NC ' -----[ Constants ]------------------------------------------------------- ' True CON 1 Press CON 1 False CON 0 NPress CON 0 Nlz CON True ' No leading zeros (in T_Out) ' LCD control pins ' E CON 5 ' LCD enable pin (1 = enabled) RS CON 4 ' Register Select (1 = char) ' LCD control characters ' ClrLCD CON $01 ' clear the LCD CrsrHm CON $02 ' move cursor to home position CrsrLf CON $10 ' move cursor left CrsrRt CON $14 ' move cursor right DispLf CON $18 ' shift displayed chars left DispRt CON $1C ' shift displayed chars right UpLin CON $80 ' goto upper line LowLin CON $C0 ' goto lower line ' Morse switch constants MLong CON 12 MShort CON 13 ButDel CON 255 ButRate CON 255 InMask CON %0011 CLK con 8 ' clock Din con 9 Dout con 10 Pwmpin con 12 MaxSiz con 4 FuktPin con 11 Ser_pin con 16 ' serial out pin (internal) ' -----[ Variables ]------------------------------------------------------- ' i VAR Byte ' index variable char VAR Byte ' char sent to LCD loop1 VAR Byte ' loop counter Butres VAR Byte ' Result from button subroutine check VAR byte ' scratch value BtLong VAR byte ' Button long result code BtShort VAR byte ' Button short result code HexNum VAR word Config var byte Adres var word Divider var word Counter var word Strout var byte(4) ' -----[ Initialization ]-------------------------------------------------- ' Init: DirL = %00111111 ' LCD pins Outs = $0000 ' all outputs off to start ' Initialize the LCD (Hitachi HD44780 controller) ' I_LCD: OutA = %0011 ' 8-bit mode PULSOUT E, 1 PAUSE 5 PULSOUT E, 1 PAUSE 5 PULSOUT E, 1 OutA = %0010 ' 4-bit mode PULSOUT E, 1 char = %00101000 ' 2-line mode GOSUB WrLCD char = %00001100 ' disp on, crsr off, blink off GOSUB WrLCD char = %00000110 ' inc crsr, no disp shift GOSUB WrLCD char = %00000001 ' clear LCD GOSUB WrLCD HIGH RS ' LCD to character mode ' -----[ Main Code ]------------------------------------------------------- ' Main: char = CrsrHm ' home the LCD cursor GOSUB LCDcmd Gosub AD_convert Gosub BinToHex char = UpLin GOSUB LCDcmd for i=1 to MaxSiz char=strout(i) Gosub WrLcd next char = LowLin GOSUB LCDcmd for i=1 to MaxSiz char=strout(i) GOSUB WrLcd next GOTO Main ' -----[ Subroutines ]-----------------------------------------------------' BinToHex: ' counter= counter+1 ' if counter <> 100 then measure ' Debug ? counter ' counter = 0 measure: for i = 1 to MaxSiz Strout(MaxSiz-i+1)=Adres //10+ $30 Adres= Adres/10 next return ' send command byte to LCD ' LCDcmd: LOW RS ' RS low = command GOSUB WrLCD ' send the byte HIGH RS ' return to character mode RETURN ' Write ASCII char to LCD ' WrLCD: OutA = char >> 4 ' output high nibble PULSOUT E, 1 ' strobe the Enable line OutA = char ' output low nibble PULSOUT E, 1 RETURN AD_convert: config = %10001110 shiftout Din,CLK,msbfirst,[config\8] ' Send config bits. shiftin Dout,CLK,msbpost,[ADres\12] ' Shift in the data. ' debug ? ADres ' Show us the conversion result. Adres = Adres * 16 / 13 return ' -----[ End ]------------------------------------------------------------- '