![]() |
Forum Index : Microcontroller and PC projects : uM2(+): KS0108, ST7920 GLCD drivers
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10066 |
Just to get all drivers up to a level I've implemented loadable versions of the GLCD drivers. As with the other monochrome displays colours are either 0 or anything-else. First the venerable KS0108, needs 14 pins but works well. Any valid pins can be used but if 5V tolerant pins are not used they should be protected by level converters or, at least, series resistors. In the example program I am using all 5V pins on a 44-pin Micromite. KS0108 sub MM.STARTUP
' 'define the 14 pins required for the display ' const KS_RS=13 const KS_RW=32 const KS_E=35 const KS_D0=1 const KS_D1=2 const KS_D2=3 const KS_D3=4 const KS_D4=5 const KS_D5=8 const KS_D6=9 const KS_D7=12 const KS_CS1=37 const KS_CS2=38 const KS_RESET=41 ' local integer pins(13)=(KS_RS,KS_RW,KS_E,KS_D0,KS_D1,KS_D2,KS_D3,KS_D4,KS_D5,KS_D6,KS_D7,KS_CS1,KS_CS2,KS_RESET) KS0108(pins(),1) 'array of pin numbers , orientation ' orientations: LANDSCAPE 1, PORTRAIT 2, RLANDSCAPE 3, RPORTRAIT 4 end SUB ' CSUB KS0108 000002E6 'KS0108_sendbyte 27BDFFE0 AFBF001C AFB10018 AFB00014 7C048C20 323000FF 32020001 10400008 3C029D00 8C43008C 8C42001C 8C64001C 0040F809 24050006 10000007 32020002 8C43008C 8C42001C 8C64001C 0040F809 24050005 32020002 10400008 3C029D00 8C43008C 8C42001C 8C640020 0040F809 24050006 10000007 32020004 8C43008C 8C42001C 8C640020 0040F809 24050005 32020004 10400008 3C029D00 8C43008C 8C42001C 8C640024 0040F809 24050006 10000007 32020008 8C43008C 8C42001C 8C640024 0040F809 24050005 32020008 10400008 3C029D00 8C43008C 8C42001C 8C640028 0040F809 24050006 10000007 32020010 8C43008C 8C42001C 8C640028 0040F809 24050005 32020010 10400008 3C029D00 8C43008C 8C42001C 8C64002C 0040F809 24050006 10000007 32020020 8C43008C 8C42001C 8C64002C 0040F809 24050005 32020020 10400008 3C029D00 8C43008C 8C42001C 8C640030 0040F809 24050006 10000007 32100040 8C43008C 8C42001C 8C640030 0040F809 24050005 32100040 12000008 3C029D00 8C43008C 8C42001C 8C640034 0040F809 24050006 10000006 00000000 8C43008C 8C42001C 8C640034 0040F809 24050005 06210008 3C029D00 8C43008C 8C42001C 8C640038 0040F809 24050006 10000007 3C109D00 8C43008C 8C42001C 8C640038 0040F809 24050005 3C109D00 8E03008C 8E02001C 8C640018 0040F809 24050006 8E020004 0040F809 24040005 8E03008C 8E02001C 8C640018 0040F809 24050005 8E03008C 8E02001C 8C64001C 0040F809 2405FFFE 8E03008C 8E02001C 8C640020 0040F809 2405FFFE 8E03008C 8E02001C 8C640024 0040F809 2405FFFE 8E03008C 8E02001C 8C640028 0040F809 2405FFFE 8E03008C 8E02001C 8C64002C 0040F809 2405FFFE 8E03008C 8E02001C 8C640030 0040F809 2405FFFE 8E03008C 8E02001C 8C640034 0040F809 2405FFFE 8E03008C 8E02001C 8C640038 0040F809 2405FFFE 8E03008C 8E02001C 8C640014 0040F809 24050006 8E03008C 8E02001C 8C640010 0040F809 24050005 8E03008C 8E02001C 8C640018 0040F809 24050006 8E03008C 8E020020 0040F809 8C640038 5440FFFC 8E03008C 3C109D00 8E03008C 8E02001C 8C640018 0040F809 24050005 8E03008C 8E02001C 8C640014 0040F809 24050005 8E03008C 8E02001C 8C64001C 0040F809 2405FFFD 8E03008C 8E02001C 8C640020 0040F809 2405FFFD 8E03008C 8E02001C 8C640024 0040F809 2405FFFD 8E03008C 8E02001C 8C640028 0040F809 2405FFFD 8E03008C 8E02001C 8C64002C 0040F809 2405FFFD 8E03008C 8E02001C 8C640030 0040F809 2405FFFD 8E03008C 8E02001C 8C640034 0040F809 2405FFFD 8E03008C 8E02001C 8C640038 0040F809 2405FFFD 8FBF001C 8FB10018 8FB00014 03E00008 27BD0020 'KS0108_setxy 27BDFFE0 AFBF001C AFB10018 AFB00014 00808021 00A08821 3C029D00 8C43008C 8C42001C 8C640010 0040F809 24050005 36040040 7C042420 0411FEF1 00000000 362400B8 7C042420 0411FEED 00000000 8FBF001C 8FB10018 8FB00014 03E00008 27BD0020 'updatedisplay 27BDFFC8 AFBF0034 AFB70030 AFB6002C AFB50028 AFB40024 AFB30020 AFB2001C AFB10018 AFB00014 3C029D00 8C43008C 8C750000 82A20400 1040004C 8FBF0034 3C029D00 8C42001C 8C64003C 0040F809 24050006 A2A00400 02A0B021 0000A021 3C109D00 24130040 24170008 00002021 02802821 0411FFC9 00000000 02A08821 00009021 8E03008C 8E02001C 8C640010 0040F809 24050006 02321021 80440000 0411FEBE 00000000 26520001 5653FFF6 8E03008C 26940001 1697FFEC 26B50080 3C109D00 8E03008C 8E02001C 8C64003C 0040F809 24050005 8E03008C 8E02001C 8C640040 0040F809 24050006 0000A821 3C119D00 24140080 24170008 00002021 02A02821 0411FFA5 00000000 02C09821 02408021 8E23008C 8E22001C 8C640010 0040F809 24050006 02701021 80440000 0411FE9A 00000000 26100001 5614FFF6 8E23008C 26B50001 16B7FFEC 26D60080 3C029D00 8C43008C 8C42001C 8C640040 0040F809 24050005 8FBF0034 8FB70030 8FB6002C 8FB50028 8FB40024 8FB30020 8FB2001C 8FB10018 8FB00014 03E00008 27BD0038 'DrawRectangleMEM 27BDFFD0 AFBF002C AFB50028 AFB40024 AFB30020 AFB2001C AFB10018 AFB00014 00808821 00A09821 00C09021 00E0A021 3C029D00 8C42008C 8C420000 90440401 240300F5 10830009 8FB00040 3C159D00 8EA2003C 0040F809 24040500 8EA3008C AC620000 2403FFF5 A0430401 3C039D00 8C630090 80630015 24040002 14640009 24040003 2403007F 00742023 00731823 0220A021 02409821 00609021 10000012 00808821 14640008 24040004 2403007F 00718823 00729023 2403003F 00739823 10000009 0074A023 14640007 2403003F 00712023 00721823 02809021 0060A021 02608821 00809821 0232182A 14600005 0274182A 02201821 02408821 00609021 0274182A 14600005 2A230000 02601821 02809821 0060A021 2A230000 0003880B 2403007F 2A240080 0064880A 2A440000 0004900B 2A440080 0064900A 2A630000 0003980B 2403003F 2A640040 0064980A 2A840000 0004A00B 2A840040 0064A00A 0251182A 10600025 0293402A 10000028 24030001 24640007 28650000 0065200A 000428C3 000529C0 00B12821 000327C3 00042742 00643021 30C60007 00C42023 00872004 12000006 308400FF 00452821 90A60000 00862025 10000006 A0A40000 00452821 00042027 90A60000 00C42024 A0A40000 24630001 0283202A 1080FFE6 24640007 26310001 0251182A 10600004 24030001 10000007 A0430400 24070001 1100FFDC 02601821 1000FFF7 26310001 A0430400 8FBF002C 8FB50028 8FB40024 8FB30020 8FB2001C 8FB10018 8FB00014 03E00008 27BD0030 'DrawBitmapMEM 27BDFFB0 AFBF004C AFBE0048 AFB70044 AFB60040 AFB5003C AFB40038 AFB30034 AFB20030 AFB1002C AFB00028 AFA40050 00A0A821 00C08821 AFA7005C 8FB00060 8FB30068 3C029D00 8C42008C 8C420000 90440401 240300F5 10830009 8FB2006C 3C149D00 8E82003C 0040F809 24040500 8E83008C AC620000 2403FFF5 A0430401 8FA3005C 1860008F 0200B821 AFB5001C 00112023 AFA40020 70711802 2463FFFF AFA30014 AFB10024 0000B021 AFA00018 24190001 3C079D00 24080002 240A0003 1000007C 240C0004 8CE60090 80CF0015 15E80007 00602021 8CE40098 8C840000 2484FFFF 00603021 10000013 008B2023 15EA000A 00000000 8CE40094 8C840000 2484FFFF 00832023 8CE60098 8CC60000 24C6FFFF 10000008 00CB3023 15EC0006 01203021 8CE60094 8CC60000 24C6FFFF 00C33023 01202021 2C8F0080 51E0002C 24A50001 04C00029 28CF0040 51E00028 24A50001 24CF0007 28DE0000 00DE780A 000F78C3 000F79C0 01E42021 00067FC3 000F7F42 00CF3021 30C60007 00CF3023 00D93004 30C600FF 0006F027 92AF0000 01F47824 11E0000C 33DE00FF 8FAF0064 11E00005 00442021 908F0000 00CF3025 1000000E A0860000 90860000 03C6F024 1000000A A09E0000 12600005 00442021 908F0000 00CF3025 10000004 A0860000 90860000 03C6F024 A09E0000 24A50001 14B0FFB5 24630001 25AD0001 25CEFFFF 11B10010 0317C021 01B61821 24640007 28750000 0095180B 0003A8C3 0255A821 000E1FC3 00031F42 01C3A021 32940007 0283A023 0299A004 03001821 1000FFA2 00002821 8FA30010 24630001 AFA30010 14700004 256B0001 10000008 8FA40018 AFA00010 1A20FFF7 01604821 8FB80050 8FAE0014 1000FFE4 00006821 24840001 AFA40018 8FAF001C 01F77821 AFAF001C 8FA30014 8FA40020 00641821 AFA30014 8FAF0024 8FA30018 8FA4005C 10640005 02CFB021 1E00FFEA 8FAB001C 1000FFEF 8FA40018 24030001 A0430400 8FBF004C 8FBE0048 8FB70044 8FB60040 8FB5003C 8FB40038 8FB30034 8FB20030 8FB1002C 8FB00028 03E00008 27BD0050 'getFPC 27BDFFF8 AFBF0004 00852023 03E42021 ACC40000 8FBF0004 03E00008 27BD0008 'pstring 27BDFFE0 AFBF001C AFB00018 00808021 00002021 3C059D00 24A50B74 27A60010 0411FFEF 00000000 8FA40010 3C029D00 8C42002C 0040F809 02042021 8FBF001C 8FB00018 03E00008 27BD0020 'main 27BDFFC8 AFBF0034 AFB30030 AFB2002C AFB10028 AFB00024 00809021 00A08821 00002021 3C059D00 24A50BD0 27A60018 0411FFD8 00000000 3C109D00 8E020090 8E230000 A0430015 8E02003C 0040F809 24040500 8E03008C AC620000 2403FFF5 A0430401 24110010 24130048 8E02008C 02221021 8E430000 AC430000 8E03008C 02231821 8E02001C 8C640000 0040F809 24050005 8E03008C 02231821 8E020010 8C640000 24050008 0040F809 00003021 8E03008C 02231821 8E020010 8C640000 24050065 0040F809 00003021 26310004 1633FFE6 26520008 3C109D00 8E03008C 8E02001C 8C640044 0040F809 24050006 8E020004 3C110003 0040F809 26240D40 8E03008C 8E02001C 8C640044 0040F809 24050005 8E020004 0040F809 36240D40 8E03008C 8E02001C 8C640044 0040F809 24050006 8E020004 0040F809 36240D40 8E03008C 8E02001C 8C64003C 0040F809 24050006 2404003F 0411FCC3 00000000 2404FFC0 0411FCC0 00000000 8E03008C 8E02001C 8C64003C 0040F809 24050005 8E03008C 8E02001C 8C640040 0040F809 24050006 2404003F 0411FCB3 00000000 2404FFC0 0411FCB0 00000000 8E03008C 8E02001C 8C640040 0040F809 24050005 8E020090 90420015 30420001 10400008 3C029D00 8C430094 24040080 AC640000 8C420098 24030040 10000007 AC430000 8C430098 24040080 AC640000 8C420094 24030040 AC430000 8FA50018 3C029D00 8C430048 3C049D00 248405F8 00852021 AC640000 8FA50018 8C43004C 3C049D00 24840830 00852021 AC640000 8FA50018 8C430084 3C049D00 24840464 00852021 AC640000 8C430048 8C440094 8C860000 8C420098 8C470000 AFA00010 8C620000 00002021 00002821 24C6FFFF 0040F809 24E7FFFF 3C049D00 24840E48 0411FF49 00000000 8FBF0034 8FB30030 8FB2002C 8FB10028 8FB00024 03E00008 27BD0038 '.rodata 'startup 3130534B 64203830 65766972 6F6C2072 64656461 00000A0D END CSUB also the SPI ST7920 (see this thread for details of the display) ST7920 sub mm.startup ' ' GND - pins 1, 15, 20 ' 5V - pins 2, 19 ' RESET pin 17 connected to micromite (pin selectable, first parameter to ST7980) ' RS pin 4 connected to micromite (pin selectable, second parameter to ST7980) ' RW pin 5 connected to SPIout on micromite ' E pin 6 connected to SPIclk on micromite ' ' ' See http://www.thebackshed.com/forum/forum_posts.asp?TID=7343 for important wiring details ' ST7920(24,23,1) 'RESET-pin, RS-pin, Size , orientation ' orientations: LANDSCAPE 1, PORTRAIT 2, RLANDSCAPE 3, RPORTRAIT 4 ' end sub ' ' CSUB ST7920 00000260 'spi_write_command 27BDFFE0 AFBF001C AFB10018 AFB00014 309100FF 3C109D00 8E030090 8E02001C 8064002D 0040F809 24050006 8E020004 0040F809 24040005 240300F8 3C02BF80 AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 322300F0 AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 00118900 323100FF AC515820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C425820 3C109D00 8E020004 0040F809 240407D0 8E030090 8E02001C 8064002D 0040F809 24050005 8FBF001C 8FB10018 8FB00014 03E00008 27BD0020 'LCD_setxy 27BDFFE0 AFBF001C AFB20018 AFB10014 28A20020 14400004 AFB00010 24920008 10000003 24B1FFE0 00A08821 00809021 3C109D00 8E030090 8E02001C 8064002D 0040F809 24050006 8E020004 0040F809 24040005 240300F8 3C02BF80 AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 32230010 34630080 AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 00118900 323100FF AC515820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 24030080 AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 00129100 AC525820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C425820 3C109D00 8E020004 0040F809 24040032 8E030090 8E02001C 8064002D 0040F809 24050005 8FBF001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0020 'updatedisplay 27BDFFB8 AFBF0044 AFBE0040 AFB7003C AFB60038 AFB50034 AFB40030 AFB3002C AFB20028 AFB10024 AFB00020 3C029D00 8C42008C 8C560000 92C20400 10400057 3C02BF80 A2C00400 8C435830 AFA30010 8C435800 AFA30014 8C435840 AFA30018 34038060 AC435800 2403001E AC435830 24030C00 AC435840 00008821 0000A021 00008021 3C159D00 3C12BF80 241700FA 241E0001 24130004 00002021 02802821 0411FF88 00000000 8EA30090 8EA2001C 8064002D 0040F809 24050006 AE575820 8E425810 30420080 1040FFFD 00000000 8E425820 001417C3 00021742 02823821 30E70007 00E21023 005E3804 26820007 2A840000 0284100A 000220C3 000421C0 00962021 00001821 24060080 90850000 00E52824 36020001 0045800B 26310001 1633000A 00108040 001080C0 AE505820 8E425810 30420080 1040FFFD 00000000 8E425820 00008821 00008021 24630001 1466FFEE 24840001 26940001 24020040 1682FFCE 00002021 3C029D00 8C430090 8C42001C 8064002D 0040F809 24050005 3C02BF80 8FA30010 AC435830 8FA30014 AC435800 8FA30018 AC435840 8FBF0044 8FBE0040 8FB7003C 8FB60038 8FB50034 8FB40030 8FB3002C 8FB20028 8FB10024 8FB00020 03E00008 27BD0048 'DrawRectangleMEM 27BDFFD0 AFBF002C AFB50028 AFB40024 AFB30020 AFB2001C AFB10018 AFB00014 00808821 00A09821 00C09021 00E0A021 3C029D00 8C42008C 8C420000 90440401 240300F5 10830009 8FB00040 3C159D00 8EA2003C 0040F809 24040500 8EA3008C AC620000 2403FFF5 A0430401 3C039D00 8C630090 80630015 24040002 14640009 24040003 2403007F 00742023 00731823 0220A021 02409821 00609021 10000012 00808821 14640008 24040004 2403007F 00718823 00729023 2403003F 00739823 10000009 0074A023 14640007 2403003F 00712023 00721823 02809021 0060A021 02608821 00809821 0232182A 14600005 0274182A 02201821 02408821 00609021 0274182A 14600005 2A230000 02601821 02809821 0060A021 2A230000 0003880B 2403007F 2A240080 0064880A 2A440000 0004900B 2A440080 0064900A 2A630000 0003980B 2403003F 2A640040 0064980A 2A840000 0004A00B 2A840040 0064A00A 0251182A 10600025 0293402A 10000028 24030001 24640007 28650000 0065200A 000428C3 000529C0 00B12821 000327C3 00042742 00643021 30C60007 00C42023 00872004 12000006 308400FF 00452821 90A60000 00862025 10000006 A0A40000 00452821 00042027 90A60000 00C42024 A0A40000 24630001 0283202A 1080FFE6 24640007 26310001 0251182A 10600004 24030001 10000007 A0430400 24070001 1100FFDC 02601821 1000FFF7 26310001 A0430400 8FBF002C 8FB50028 8FB40024 8FB30020 8FB2001C 8FB10018 8FB00014 03E00008 27BD0030 'DrawBitmapMEM 27BDFFB0 AFBF004C AFBE0048 AFB70044 AFB60040 AFB5003C AFB40038 AFB30034 AFB20030 AFB1002C AFB00028 AFA40050 00A0A821 00C08821 AFA7005C 8FB00060 8FB30068 3C029D00 8C42008C 8C420000 90440401 240300F5 10830009 8FB2006C 3C149D00 8E82003C 0040F809 24040500 8E83008C AC620000 2403FFF5 A0430401 8FA3005C 1860008F 0200B821 AFB5001C 00112023 AFA40020 70711802 2463FFFF AFA30014 AFB10024 0000B021 AFA00018 24190001 3C079D00 24080002 240A0003 1000007C 240C0004 8CE60090 80CF0015 15E80007 00602021 8CE40098 8C840000 2484FFFF 00603021 10000013 008B2023 15EA000A 00000000 8CE40094 8C840000 2484FFFF 00832023 8CE60098 8CC60000 24C6FFFF 10000008 00CB3023 15EC0006 01203021 8CE60094 8CC60000 24C6FFFF 00C33023 01202021 2C8F0080 51E0002C 24A50001 04C00029 28CF0040 51E00028 24A50001 24CF0007 28DE0000 00DE780A 000F78C3 000F79C0 01E42021 00067FC3 000F7F42 00CF3021 30C60007 00CF3023 00D93004 30C600FF 0006F027 92AF0000 01F47824 11E0000C 33DE00FF 8FAF0064 11E00005 00442021 908F0000 00CF3025 1000000E A0860000 90860000 03C6F024 1000000A A09E0000 12600005 00442021 908F0000 00CF3025 10000004 A0860000 90860000 03C6F024 A09E0000 24A50001 14B0FFB5 24630001 25AD0001 25CEFFFF 11B10010 0317C021 01B61821 24640007 28750000 0095180B 0003A8C3 0255A821 000E1FC3 00031F42 01C3A021 32940007 0283A023 0299A004 03001821 1000FFA2 00002821 8FA30010 24630001 AFA30010 14700004 256B0001 10000008 8FA40018 AFA00010 1A20FFF7 01604821 8FB80050 8FAE0014 1000FFE4 00006821 24840001 AFA40018 8FAF001C 01F77821 AFAF001C 8FA30014 8FA40020 00641821 AFA30014 8FAF0024 8FA30018 8FA4005C 10640005 02CFB021 1E00FFEA 8FAB001C 1000FFEF 8FA40018 24030001 A0430400 8FBF004C 8FBE0048 8FB70044 8FB60040 8FB5003C 8FB40038 8FB30034 8FB20030 8FB1002C 8FB00028 03E00008 27BD0050 'getFPC 27BDFFF8 AFBF0004 00852023 03E42021 ACC40000 8FBF0004 03E00008 27BD0008 'pstring 27BDFFE0 AFBF001C AFB00018 00808021 00002021 3C059D00 24A5095C 27A60010 0411FFEF 00000000 8FA40010 3C029D00 8C42002C 0040F809 02042021 8FBF001C 8FB00018 03E00008 27BD0020 'main 27BDFFC8 AFBF0034 AFB40030 AFB3002C AFB20028 AFB10024 AFB00020 00808021 00A08821 00C09021 00002021 3C059D00 24A509C0 27A60018 0411FFD6 00000000 3C029D00 8C430090 8E040000 A064002E 8C430090 8E240000 A064002D 8C430090 8E440000 A0640015 8C42003C 0040F809 24040500 2403FFF5 A0430401 00401821 24440500 A0600000 24630001 5464FFFE A0600000 3C109D00 8E03008C AC620000 8E030090 8E020010 8064002E 24050008 0040F809 00003021 8E030090 8E020010 8064002E 24050065 0040F809 00003021 8E030090 8E02001C 8064002E 0040F809 24050006 8E030090 8E020010 8064002D 24050008 0040F809 00003021 8E030090 8E020010 8064002D 24050065 0040F809 00003021 8E030090 8E02001C 8064002D 0040F809 24050005 3C02BF81 8C44F220 7C84D800 3C030661 3463A053 1083000A 24020050 3C02BF81 8C44F220 7C84D800 3C020660 3442A053 00822026 24030050 2402000C 0064100A 3C039D00 8C630088 00431021 8C430000 24020064 54620007 00009021 3C02BF80 8C525830 8C535800 8C545840 10000003 3C029D00 00009821 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661 3463A053 10A3000A 24040014 3C03BF81 8C65F220 7CA5D800 3C030660 3463A053 00A32826 24030014 24040003 0065200A 24050008 0040F809 00003021 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661 3463A053 10A3000A 24040014 3C03BF81 8C65F220 7CA5D800 3C030660 3463A053 00A32826 24030014 24040003 0065200A 24050065 0040F809 00003021 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661 3463A053 10A3000A 24040029 3C03BF81 8C65F220 7CA5D800 3C030660 3463A053 00A32826 24030029 2404000E 0065200A 24050002 0040F809 00003021 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661 3463A053 10A3000A 24040029 3C03BF81 8C65F220 7CA5D800 3C030660 3463A053 00A32826 24030029 2404000E 0065200A 24050065 0040F809 00003021 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661 3463A053 10A3000A 2404000E 3C03BF81 8C65F220 7CA5D800 3C030660 3463A053 00A32826 2403000E 24040019 0065200A 24050008 0040F809 00003021 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661 3463A053 10A3000A 2404000E 3C03BF81 8C65F220 7CA5D800 3C030660 3463A053 00A32826 2403000E 24040019 0065200A 24050065 0040F809 00003021 3C02BF81 8C43FA84 24040001 7C831804 AC43FA84 3C02BF81 8C43FB04 24040003 7C831804 AC43FB04 3C02BF80 34038060 AC435800 24030030 AC435830 24030C00 AC435840 16400005 3C109D00 8C525830 8C535800 8C545840 3C109D00 8E030090 8E02001C 8064002E 0040F809 24050006 8E020004 3C110003 0040F809 26240D40 8E030090 8E02001C 8064002E 0040F809 24050005 8E020004 0040F809 36240D40 8E030090 8E02001C 8064002E 0040F809 24050006 8E020004 0040F809 36240D40 24040001 0411FC88 00000000 2404000C 0411FC85 00000000 24040001 0411FC82 00000000 24040026 0411FC7F 00000000 8E020090 90420015 30420001 10400008 3C029D00 8C430094 24040080 AC640000 8C420098 24030040 10000007 AC430000 8C430098 24040080 AC640000 8C420094 24030040 AC430000 8FA50018 3C029D00 8C430048 3C049D00 248403E0 00852021 AC640000 8FA50018 8C43004C 3C049D00 24840618 00852021 AC640000 8FA50018 8C430084 3C049D00 24840214 00852021 AC640000 8C430048 8C440094 8C860000 8C420098 8C470000 AFA00010 8C620000 00002021 00002821 24C6FFFF 0040F809 24E7FFFF 3C02BF80 AC525830 AC535800 AC545840 3C049D00 24840F0C 0411FE93 00000000 8FBF0034 8FB40030 8FB3002C 8FB20028 8FB10024 8FB00020 03E00008 27BD0038 '.rodata 'startup 39375453 64203032 65766972 6F6C2072 64656461 00000A0D End CSUB c-source for the KS0108 /*******************************************************************************
* * Driver for KS0108 Display written as CFunctions * * Author: Peter Mather 2015 with acknowledgements to Peter Carnegie & Geoff Graham * * * This CFunction MUST be compiled with Optimization Level 1, -O1 * -O2,-O3,-Os will compile successfully, but generate exceptions at runtime. * * When Generating the CFunction, use MERGE CFunction mode, and name the CFunction * KS0108 * * Entry point is function void main(long long *pins * long long *orientation) * * V1.0 2015-03-04 Peter Mather ******************************************************************************/ #include <stdarg.h> #define Version 100 //Version 1.00 #define _SUPPRESS_PLIB_WARNING // required for XC1.33 Later compiler versions will need PLIB to be installed #include <plib.h> // the pre Harmony peripheral libraries #include "../cfunctions.h" #define LANDSCAPE 1 #define PORTRAIT 2 #define RLANDSCAPE 3 #define RPORTRAIT 4 #define screenwidth 128 #define screenheight 64 #define screenrows screenheight/8 #define update screenwidth*screenrows //location for status to force screen write #define magic update+1 #define RS 4 #define RW 5 #define E 6 #define DB0 7 #define DB1 8 #define DB2 9 #define DB3 10 #define DB4 11 #define DB5 12 #define DB6 13 #define DB7 14 #define CS1 15 #define CS2 16 #define RESET 17 void KS0108_sendbyte(char x){ if(x & 1)PinSetBit(CFuncRam[DB0],LATSET); else PinSetBit(CFuncRam[DB0],LATCLR); if(x & 2)PinSetBit(CFuncRam[DB1],LATSET); else PinSetBit(CFuncRam[DB1],LATCLR); if(x & 4)PinSetBit(CFuncRam[DB2],LATSET); else PinSetBit(CFuncRam[DB2],LATCLR); if(x & 8)PinSetBit(CFuncRam[DB3],LATSET); else PinSetBit(CFuncRam[DB3],LATCLR); if(x & 16)PinSetBit(CFuncRam[DB4],LATSET); else PinSetBit(CFuncRam[DB4],LATCLR); if(x & 32)PinSetBit(CFuncRam[DB5],LATSET); else PinSetBit(CFuncRam[DB5],LATCLR); if(x & 64)PinSetBit(CFuncRam[DB6],LATSET); else PinSetBit(CFuncRam[DB6],LATCLR); if(x & 128)PinSetBit(CFuncRam[DB7],LATSET); else PinSetBit(CFuncRam[DB7],LATCLR); PinSetBit(CFuncRam[E],LATSET); uSec(5); PinSetBit(CFuncRam[E],LATCLR); PinSetBit(CFuncRam[DB0],TRISSET); PinSetBit(CFuncRam[DB1],TRISSET); PinSetBit(CFuncRam[DB2],TRISSET); PinSetBit(CFuncRam[DB3],TRISSET); PinSetBit(CFuncRam[DB4],TRISSET); PinSetBit(CFuncRam[DB5],TRISSET); PinSetBit(CFuncRam[DB6],TRISSET); PinSetBit(CFuncRam[DB7],TRISSET); PinSetBit(CFuncRam[RW],LATSET); PinSetBit(CFuncRam[RS],LATCLR); PinSetBit(CFuncRam[E],LATSET); while(PinRead(CFuncRam[DB7])); PinSetBit(CFuncRam[E],LATCLR); PinSetBit(CFuncRam[RW],LATCLR); PinSetBit(CFuncRam[DB0],TRISCLR); PinSetBit(CFuncRam[DB1],TRISCLR); PinSetBit(CFuncRam[DB2],TRISCLR); PinSetBit(CFuncRam[DB3],TRISCLR); PinSetBit(CFuncRam[DB4],TRISCLR); PinSetBit(CFuncRam[DB5],TRISCLR); PinSetBit(CFuncRam[DB6],TRISCLR); PinSetBit(CFuncRam[DB7],TRISCLR); } void KS0108_setxy(int x,int y){ int i=0x40 | x; PinSetBit(CFuncRam[RS],LATCLR); KS0108_sendbyte(i); i=0xB8 | y; KS0108_sendbyte(i); } void updatedisplay(void){ char* p=(void *)(unsigned int)CFuncRam[0]; if(p[update]){ PinSetBit(CFuncRam[CS1],LATSET); char *q; int j,n; p[update]=0; for(n=0;n<screenrows;n++){ KS0108_setxy(0,n); q=p+n*screenwidth; for(j=0;j<screenwidth/2;j++){ PinSetBit(CFuncRam[RS],LATSET); KS0108_sendbyte(q[j]); } } PinSetBit(CFuncRam[CS1],LATCLR); PinSetBit(CFuncRam[CS2],LATSET); for(n=0;n<screenrows;n++){ KS0108_setxy(0,n); q=p+n*screenwidth; for(j=screenwidth/2;j<screenwidth;j++){ PinSetBit(CFuncRam[RS],LATSET); KS0108_sendbyte(q[j]); } } PinSetBit(CFuncRam[CS2],LATCLR); } } long long DrawRectangleMEM(int x1, int y1, int x2, int y2, int c){ unsigned char* p=(void *)(unsigned int)CFuncRam[0]; if(p[magic]!=0xF5){ p = GetMemory(screenwidth*screenheight/8+256); //Save the address for other CFunctions CFuncRam[0]=(unsigned int)(p); p[magic]=0xF5; } int i,j,loc,t; unsigned char mask; if(Option->DISPLAY_ORIENTATION==PORTRAIT){ t=x1; x1=screenwidth-y2-1; y2=t; t=x2; x2=screenwidth-y1-1; y1=t; } if(Option->DISPLAY_ORIENTATION==RLANDSCAPE){ x1=screenwidth-x1-1; x2=screenwidth-x2-1; y1=screenheight-y1-1; y2=screenheight-y2-1; } if(Option->DISPLAY_ORIENTATION==RPORTRAIT){ t=y1; y1=screenheight-x1-1; x1=t; t=y2; y2=screenheight-x2-1; x2=t; } if(x2 <= x1) { t = x1; x1 = x2; x2 = t; } if(y2 <= y1) { t = y1; y1 = y2; y2 = t; } if(x1 < 0) x1 = 0; if(x1 >= screenwidth) x1 = screenwidth - 1; if(x2 < 0) x2 = 0; if(x2 >= screenwidth) x2 = screenwidth - 1; if(y1 < 0) y1 = 0; if(y1 >= screenheight) y1 = screenheight - 1; if(y2 < 0) y2 = 0; if(y2 >= screenheight) y2 = screenheight - 1; for(i=x1;i<=x2;i++){ for(j=y1;j<=y2;j++){ loc=i+(j/8)*screenwidth; //get the byte address for this bit mask=1<<(j % 8); //get the bit position for this bit if(c){ p[loc]|=mask; } else { p[loc]&=(~mask); } } } p[update]=1; } void DrawBitmapMEM(int x1, int y1, int width, int height, int scale, int fc, int bc, unsigned char *bitmap){ int i, j, k, m, x, y,t, loc; unsigned char omask, amask; unsigned char* p=(void *)(unsigned int)CFuncRam[0]; if(p[magic]!=0xF5){ p = GetMemory(screenwidth*screenheight/8+256); //Save the address for other CFunctions CFuncRam[0]=(unsigned int)(p); p[magic]=0xF5; } for(i = 0; i < height; i++) { // step thru the font scan line by line for(j = 0; j < scale; j++) { // repeat lines to scale the font for(k = 0; k < width; k++) { // step through each bit in a scan line for(m = 0; m < scale; m++) { // repeat pixels to scale in the x axis x=x1 + k * scale + m ; y=y1 + i * scale + j ; if(Option->DISPLAY_ORIENTATION==PORTRAIT){ t=x; x=VRes-y-1; y=t; } if(Option->DISPLAY_ORIENTATION==RLANDSCAPE){ x=HRes-x-1; y=VRes-y-1; } if(Option->DISPLAY_ORIENTATION==RPORTRAIT){ t=y; y=HRes-x-1; x=t; } loc=x+(y/8)*screenwidth; //get the byte address for this bit omask=1<<(y % 8); //get the bit position for this bit amask=~omask; if(x >= 0 && x < screenwidth && y >= 0 && y < screenheight) { // if the coordinates are valid if((bitmap[((i * width) + k)/8] >> (((height * width) - ((i * width) + k) - 1) %8)) & 1) { if(fc){ p[loc]|=omask; } else { p[loc]&=amask; } } else { if(bc){ p[loc]|=omask; } else { p[loc]&=amask; } } } } } } } p[update]=1; } __attribute__((noinline)) void getFPC(void *a, void *b, volatile unsigned int *c) { *c = (unsigned int) (__builtin_return_address (0) - (b -a)) ; } void pstring(const char *s){ volatile unsigned int libAddr ; getFPC(NULL,&&getFPCLab,&libAddr) ; // warning can be ignored, stupid editor getFPCLab: { } unsigned char * testData = (unsigned char *)((void *)s + libAddr ); MMPrintString(testData); } void main(long long *pins, long long *orientation){ volatile unsigned int libAddr ; getFPC(NULL,&&getFPCLab,&libAddr) ; // warning can be ignored, stupid editor getFPCLab: { } int j,HorizontalRes=screenwidth,VerticalRes=screenheight; Option->DISPLAY_ORIENTATION=*orientation; //Get some persistent memory unsigned char * p = GetMemory(HorizontalRes*VerticalRes/8+256); //Save the address for other CFunctions CFuncRam[0]=(unsigned int)(p); p[magic]=0xF5; for(j=4;j<=RESET;j++){ CFuncRam[j]=pins[j-4]; PinSetBit(CFuncRam[j], LATCLR); ExtCfg(CFuncRam[j],EXT_DIG_OUT,0);ExtCfg(CFuncRam[j],EXT_BOOT_RESERVED,0); } PinSetBit(CFuncRam[RESET],LATSET); uSec(200000); PinSetBit(CFuncRam[RESET],LATCLR); uSec(200000); PinSetBit(CFuncRam[RESET],LATSET); uSec(200000); PinSetBit(CFuncRam[CS1],LATSET); KS0108_sendbyte(0x3F); //display on KS0108_sendbyte(0xC0); //display start line zero PinSetBit(CFuncRam[CS1],LATCLR); PinSetBit(CFuncRam[CS2],LATSET); KS0108_sendbyte(0x3F); //display on KS0108_sendbyte(0xC0); //display start line zero PinSetBit(CFuncRam[CS2],LATCLR); if(Option->DISPLAY_ORIENTATION&1){ HRes=HorizontalRes; VRes=VerticalRes; } else { VRes=HorizontalRes; HRes=VerticalRes; } //Set the DrawRectangle vector to point to our function DrawRectangleVector= (unsigned int)&DrawRectangleMEM + libAddr; //Set the DrawBitmap vector to point to our function DrawBitmapVector=(unsigned int)&DrawBitmapMEM + libAddr; CFuncmSec=(unsigned int)&updatedisplay + libAddr; //CLS DrawRectangle(0,0,HRes-1,VRes-1,0); static const char startup[]="KS0108 driver loaded\r\n"; pstring(startup); } |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |