{"id":3200,"date":"2012-03-25T22:31:46","date_gmt":"2012-03-26T02:31:46","guid":{"rendered":"https:\/\/example.com\/?postname=stm8l-char-lcd-code-contributed-by-nick-deroller"},"modified":"2012-03-25T22:31:46","modified_gmt":"2012-03-26T02:31:46","slug":"stm8l-char-lcd-code-contributed-by-nick-deroller","status":"publish","type":"post","link":"http:\/\/atomsofttech.com\/blog\/uncategorized\/stm8l-char-lcd-code-contributed-by-nick-deroller\/","title":{"rendered":"STM8L Char-LCD Code: Contributed by Nick DeRoller"},"content":{"rendered":"<p>I know there are tons of comments and sites around with people looking for some code for the STM8. Lets thank Nick DeRoller for contributing this code to us all.<\/p>\n<pre>\/\/ Run LCD from STM8L sample code\n\/\/ Runs 2x16 charicter display in 4-bit mode\n\/\/ Utilizes waits\n\/\/ Created by: Jason Lopez\n\/\/ Edited for STM8L by: Nick DeRoller\n\n\/\/ Hardware Connections:\n\/\/ E\u00a0\u00a0 -&gt; PB0\n\/\/ R\/W -&gt; PB1\n\/\/ DB4 -&gt; PB4\n\/\/ DB5 -&gt; PB5\n\/\/ DB6 -&gt; PB6\n\/\/ DB7 -&gt; PB7\n\n\/\/ Requires 'stm8l15x_gpio.c'\n\/\/ All other drivers may be excluded from the build to \n\/\/ speed build time.\n\n\/\/ Compiled using Raisonance\n\n#include \"stm8l15x.h\"\n\n#define LCD_PORT GPIOB\n#define LCD_RS GPIO_Pin_0\n#define LCD_E GPIO_Pin_1\n\n#define GPIO_HIGH(a,b) \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0a-&gt;ODR|=b\n#define GPIO_LOW(a,b)\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0a-&gt;ODR&amp;=~b\n\nvoid DelayMS(int delay);\nvoid initLCD(void);\nvoid LCD_DATA(unsigned char varData,unsigned char varType);\nvoid LCD_NYB(unsigned char nyb, char varType);\nvoid LCD_LINE(char line);\nvoid LCD_STR(const unsigned char *text);\n\nvoid main(void) {\n\u00a0\u00a0 \u00a0\n\u00a0\u00a0 \u00a0GPIO_DeInit(LCD_PORT);\n\u00a0\u00a0 \u00a0GPIO_Init(LCD_PORT, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);\n\u00a0\u00a0 \u00a0initLCD();\n\u00a0\u00a0 \u00a0\n\u00a0\u00a0 \u00a0LCD_LINE(1);\n\u00a0\u00a0 \u00a0LCD_STR(\" AtomSoftTech \");\n\u00a0\u00a0 \u00a0DelayMS(100);\n\u00a0\u00a0 \u00a0LCD_LINE(2);\n\u00a0\u00a0 \u00a0LCD_STR(\" Jason Lopez \");\n\u00a0\u00a0 \u00a0DelayMS(100);\n\u00a0\u00a0 \u00a0\n\u00a0\u00a0 \u00a0while(1);\n}\n\nvoid LCD_STR(const unsigned char *text){\n\u00a0\u00a0 \u00a0while(*text){\n\u00a0\u00a0 \u00a0LCD_DATA(*text++,1);\n\u00a0\u00a0 \u00a0}\n}\n\nvoid initLCD(void){\n\u00a0\u00a0 \u00a0GPIO_LOW(LCD_PORT,LCD_E); \u00a0\u00a0 \u00a0\/\/clear enable\n\u00a0\u00a0 \u00a0GPIO_LOW(LCD_PORT,LCD_RS); \u00a0\u00a0 \u00a0\/\/going to write command\n\u00a0\u00a0 \u00a0DelayMS(30);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/delay for LCD to initialise.\n\u00a0\u00a0 \u00a0LCD_NYB(0x03,0);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/Required for initialisation\n\u00a0\u00a0 \u00a0DelayMS(5);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/required delay\n\u00a0\u00a0 \u00a0LCD_NYB(0x03,0);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/Required for initialisation\n\u00a0\u00a0 \u00a0DelayMS(1);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/required delay\n\u00a0\u00a0 \u00a0LCD_DATA(0x02,0);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/set to 4 bit interface, 1 line and 5*7 font\n\u00a0\u00a0 \u00a0LCD_DATA(0x28,0);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/set to 4 bit interface, 2 line and 5*10 font\n\u00a0\u00a0 \u00a0LCD_DATA(0x0c,0);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/set to 4 bit interface, 2 line and 5*7 font\n\u00a0\u00a0 \u00a0LCD_DATA(0x01,0);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/clear display\n\u00a0\u00a0 \u00a0LCD_DATA(0x06,0);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/move cursor right after write\n}\n\n\nvoid LCD_DATA(unsigned char varData,unsigned char varType)\n{\n\u00a0\u00a0 \u00a0DelayMS(10);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/TEST LCD FOR BUSY\n\u00a0\u00a0 \u00a0LCD_NYB(varData &gt;&gt; 4,varType);\u00a0\u00a0 \u00a0\/\/WRITE THE UPPER NIBBLE\n\u00a0\u00a0 \u00a0LCD_NYB(varData,varType);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/WRITE THE LOWER NIBBLE\n}\n\n\nvoid LCD_NYB(unsigned char nyb, char varType){\n\u00a0\u00a0 \u00a0unsigned char temp;\n\u00a0\u00a0 \u00a0temp = (nyb&lt;&lt;4) &amp; 0xF0;\n\u00a0\u00a0 \u00a0GPIO_Write(LCD_PORT,temp);\n\u00a0\u00a0 \u00a0\n\u00a0\u00a0 \u00a0if(varType == 0){\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0GPIO_LOW(LCD_PORT,LCD_RS);\u00a0\u00a0 \u00a0\/\/COMMAND MODE\n\u00a0\u00a0 \u00a0} else {\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0GPIO_HIGH(LCD_PORT,LCD_RS);\u00a0\u00a0 \u00a0\/\/CHARACTER\/DATA MODE\n\u00a0\u00a0 \u00a0}\n\u00a0\u00a0 \u00a0\n\u00a0\u00a0 \u00a0GPIO_HIGH(LCD_PORT,LCD_E);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ENABLE LCD DATA LINE\n\u00a0\u00a0 \u00a0DelayMS(1);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/SMALL DELAY\n\u00a0\u00a0 \u00a0GPIO_LOW(LCD_PORT,LCD_E);\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/DISABLE LCD DATA LINE\n\n}\nvoid LCD_LINE(char line){\n\u00a0\u00a0 \u00a0switch(line){\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0case 0:\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0case 1:\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0LCD_DATA(0x80,0);\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0break;\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0case 2:\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0LCD_DATA(0xC0,0);\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0break;\n\u00a0\u00a0 \u00a0}\n}\nvoid DelayMS(int delay){\n\u00a0\u00a0 \u00a0int nCount = 0;\n\u00a0\u00a0 \u00a0while (delay != 0){\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0nCount = 100;\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0while (nCount != 0){\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0nCount--;\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0delay--;\n\u00a0\u00a0 \u00a0}\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I know there are tons of comments and sites around with people looking for some code for the STM8. Lets thank Nick DeRoller for contributing this code to us all. \/\/ Run LCD from STM8L sample code \/\/ Runs 2&#215;16 charicter display in 4-bit mode \/\/ Utilizes waits \/\/ Created by: Jason Lopez \/\/ Edited [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-3200","post","type-post","status-publish","format-standard","hentry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/posts\/3200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/comments?post=3200"}],"version-history":[{"count":0,"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/posts\/3200\/revisions"}],"wp:attachment":[{"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/media?parent=3200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/categories?post=3200"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/atomsofttech.com\/blog\/wp-json\/wp\/v2\/tags?post=3200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}