'Filename EADIP203_002.bas 'Version 0.02 'Date 2018-04-24 'Purpose Test special initialization of EA DIP203-4 LCD (SSD1803 controller) ' Initialization programmed for EA DIP204-4 (KS0073 controller) at first ' works with EA DIP203-4 as well, i.e. controllers are compatible. 'Author Georg Latzel, DL6GL 'Copyright (c) Georg Latzel, free for private use under GNU license 'Hardware ATmega32, was just on the test board ' Crystal 16 MHz ' 4x20 Text LCD EA DIP203-4 @ PortB 'Compiler BASCOM-AVR 2.0.7.6 ' For readable "camel case" variables mark "Don't change case" ' in BASCOM Options-Programmer-Environment-Editor ' Flash used: 3,616 bytes 'Edit history '============================================================================== 'FUSE-Bits (AVR Studio 4.0-Settings, [ ]=no check, [x]=check) 'In ATMEGA-Data sheets: Bit = 1 -> not set ' Bit = 0 -> set 'OCDEN [ ] 'JTAGEN [ ] (disabled) 'SPIEN [x] Do not change! 'CKOPT [ ] 'EESAVE [ ] 'BOOTSZ Boot Flash size=256 words (minimal boot size) 'BOOTRST [ ] 'BODLEVEL Brown-out detection at VCC=4.0V 'SUT_CKSEL Ext. Crystal High Freq., Start-up time 16k + 64ms 'Fuses high 0xDF 'Fuses low 0x7F $regfile = "m32def.dat" 'ATMega32 $crystal = 16000000 '16 MHz xtal $hwstack = 40 $swstack = 40 $framesize = 40 'Configure PortA -------------------------------------------------------------- DDRA = &B00000000 'PortA = Input PortA = &B11111111 'activate Pullup 0...7 'Special 20x4 Text LCD EA DIP203-4 LCD with SSD1803 controller (4 bit mode) --- LCD_RS Alias PortB.2 'LCD pin RS LCD_E Alias PortB.3 'LCD pin E LCD_D7 Alias PortB.4 'LCD pin DB7 LCD_D6 Alias PortB.5 'LCD pin DB6 LCD_D5 Alias PortB.6 'LCD pin DB5 LCD_D4 Alias PortB.7 'LCD pin DB4 Config Lcdpin = Pin , Db7 = LCD_D7 , Db6 = LCD_D6 , Db5 = LCD_D5 , Db4 = LCD_D4 Config Lcdpin = Pin , E = LCD_E , Rs = LCD_RS Config Lcdbus = 4 Config Lcd = 20 * 4A , Chipset = KS077 'Special for EA DIP203 'Configure PortC -------------------------------------------------------------- DDRC = &B00000000 'PortC = Input PortC = &B11111111 'activate Pullup 0...7 'Configure PortD -------------------------------------------------------------- DDRD = &B00000000 'PortD = Input PortD = &B11111111 'activate Pullup 0...7 'LCD bargraph calibration ----------------------------------------------------- '20 char display '1 character = 5 dots Const bytChar = 20 'Number of display characters Const bytDots = 5 'bar dots per character Const bytBarLen = 15 'Bar length (characters) Const bytRowSWR = 4 'Row for SWR display 'Common Variables, multiply used ---------------------------------------------- Dim bytTmp0 As Byte Dim wrdTmp0 As Word Dim wrdTmp1 As Word Dim wrdTmp2 As Word Dim sngTmp0 As Single Dim strDis As String * 20 'Text to be dispayed on LCD Dim bytDis(20) As Byte At strDis Overlay 'the same as byte-array Dim strTmp10 As String * 10 Dim bytTmp10(10) As Byte At strTmp10 Overlay 'Variables for SWR bar graph -------------------------------------------------- Dim strBar(5) As String * 1 'Bars 1...5 columns width Dim sngSWR As Single Dim sngSWRBarCal As Single 'SWR bar scale factor Const sngSWRBarMax = 3 'Max SWR for bargraph 'Declare subs & functions ----------------------------------------------------- Declare Sub LCDInit Declare Sub LCDWriteInstruction(byVal bytLCDChar As Byte) Declare Sub LCDWriteNibble(byVal bytLCDChar As Byte) Declare Sub ClearLCDLine(byVal bytRow As Byte , byVal bytChars As Byte) Declare Sub ShowSWR(byVal bytRowS As Byte) 'Bars for EA DIP203-4 & EA DIP204-4 LCD, see character table ------------------ strBar(1) = Chr(218) '1 bar strBar(2) = Chr(217) '2 bars strBar(3) = Chr(216) '3 bars strBar(4) = Chr(215) '4 bars strBar(5) = Chr(214) '5 bars (full) Call LCDInit 'Special init for DIP20x-4 LCD Cls Cursor Off Locate 1 , 1 LCD "EADIP203 002.bas" Locate 2 , 1 LCD "12345678901234567890" Locate 3 , 1 LCD "abcdefghijklmnopqrst" Locate 4 , 1 LCD "!'§$%&/()=**+~######" Wait 2 Call ClearLCDLine(2 , bytChar) Call ClearLCDLine(3 , bytChar) sngSWRBarCal = bytBarLen * bytDots 'SWR bar dots (5 per character) sngTmp0 = sngSWRBarMax - 1 sngSWRBarCal = sngSWRBarCal / sngTmp0 'SWR bar calibration, SWR=1 suppressed Do 'Show SWR bar graph sngSWR = 1 Call ClearLCDLine(4 , bytChar) Do sngSWR = sngSWR + 0.1 Call ShowSWR(bytRowSWR) Waitms 300 Loop Until sngSWR > 3 Wait 1 Loop End '====================================================================== LCDInit Sub LCDInit 'Special initialization for EA DIP203-4 or EA DIP204-4 Waitms 50 'Wait for power up if just started Call LCDWriteInstruction(&B00101100) 'Function set RE=1 Call LCDWriteInstruction(&B00001001) 'Extended function set, 4 lines, 5dot Call LCDWriteInstruction(&B00101000) 'Function set RE=0 Call LCDWriteInstruction(&B00000110) 'Entry mode set cursor auto-increment Call LCDWriteInstruction(&B00001100) 'Display on, cursor off, blink off End Sub '=============================================================== LCDWriteNibble Sub LCDWriteNibble(byVal bytLCDChar As Byte) 'Write 4 high bits (high nibble) of byte bytLCDChar to 4 bit mode LCD LCD_D4 = bytLCDChar.4 LCD_D5 = bytLCDChar.5 LCD_D6 = bytLCDChar.6 LCD_D7 = bytLCDChar.7 LCD_E = 1 'Enable, send high nibble Waitms 2 'Wait for LCD to execute LCD_E = 0 End Sub '========================================================== LCDWriteInstruction Sub LCDWriteInstruction(byVal bytLCDChar As Byte) 'Send instruction to 4 bit mode LCD. First high nibble, then low nibble Call LCDWriteNibble(bytLCDChar) 'High nibble Waitms 1 'Wait for LCD to execute Shift bytLCDChar , Left , 4 'Shift low nibble up 4 bits Call LCDWriteNibble(bytLCDChar) 'Low nibble is now at high position End Sub '============================================================================== Sub ClearLCDLine(byVal bytRow As Byte , byVal bytChars As Byte) 'Clear LCD bytChars characters in line bytRow Locate bytRow , 1 LCD SPC(bytChars) Locate bytRow , 1 End Sub '================================================================= ShowSWRPower Sub ShowSWR(byVal bytRowS As Byte) 'Show SWR bar graph 'Input: bytRowS LCD row for SWR bar display ' sngSWR SWR ' sngSWRBarMax Max SWR for Bar ' sngSWRBarCal Bar calibration 'SWR ----------------------------------------------------------------------- If sngSWR > 9.99 Then sngSWR = 9.99 'SWR display limit End If If sngSWR > sngSWRBarMax Then 'Suppress bargraph for SWR = 1 sngTmp0 = sngSWRBarMax - 1 'Display limit Else sngTmp0 = sngSWR - 1 'Current SWR End If sngTmp0 = sngSWRBarCal * sngTmp0 'Bar calibration wrdTmp2 = sngTmp0 'Number of bar dots wrdTmp0 = wrdTmp2 / 5 'Number of 5 dot full blocks wrdTmp1 = wrdTmp2 Mod 5 'Remaining partial single bars strDis = "" If wrdTmp0 > 0 Then 'Full 5 dot blocks For bytTmp0 = 1 To wrdTmp0 strDis = strDis + strBar(5) Next bytTmp0 End If If wrdTmp1 > 0 Then strDis = strDis + strBar(wrdTmp1) 'Last bar(s) < 5 dots End If wrdTmp1 = bytBarLen - 4 'Space for Tag 'SWR'? If wrdTmp0 < wrdTmp1 Then bytTmp0 = 1 'yes Else bytTmp0 = 0 'no End If wrdTmp0 = Len(strDis) 'string length up to now wrdTmp1 = bytChar - wrdTmp0 'remaining characters wrdTmp1 = wrdTmp1 - 4 '4 char's for value If wrdTmp1 > 0 Then strDis = strDis + Space(wrdTmp1) 'Fill with spaces End If If bytTmp0 = 1 Then 'Add tag 'SWR' wrdTmp0 = Len(strDis) wrdTmp1 = wrdTmp0 - 4 strDis = Left(strDis , wrdTmp1) strDis = strDis + "SWR " End If wrdTmp0 = sngSWR * 100 'show 2 decimals strTmp10 = str(wrdTmp0) strTmp10 = Format(strTmp10 , "0.00") strDis = strDis + strTmp10 'Add sngSWR value at the end Locate bytRowS , 1 LCD strDis 'Show me End Sub