LCD program structure :S - Page 1
Forum section: electronics / general

author: tahmod
author_rank: Contributor
timestamp: April 12, 2013, 07:24:09 pm
content: I want to learn to program a LCD and I am doing a tutorial.-How can I understand this code below?-what is the main structure to understand for a LCD?;************************************************************************;* Microchip Technology Inc. 2007 *;* Assembler version: x.x *;* Filename: *;* lcd.asm (main routine) *;* Dependents: *;* Main.asm *;* Modified Jan 2013 *;* PICDEM Explorer DEMO code. *;* *;************************************************************************#ifdef __18F8722list p=18F8722#include p18F8722.inc#endif#ifdef __18F87J11list p=18F87J11#include p18F87J11.inc#endif#define LCD_E temp_reg, 6 ; LCD E clock#define LCD_RS temp_reg, 7 ; LCD register select line#define LCD_CS LATA,2 ; LCD chip select#define LCD_CS_TRIS TRISA,2 ; LCD chip select#define LCD_RST LATF,6 ; LCD chip select#define LCD_RST_TRIS TRISF,6 ; LCD chip selectD_LCD_DATA UDATA_ACSdelay res 1temp_wr res 1temp_rd res 1Dreg1 res 1Dreg2 res 1temp_reg res 1GLOBAL temp_wrPROG1 CODE;---------------------------------------------------------------;LCD Initialization routine;---------------------------------------------------------------global LCDInitLCDInitbcf LCD_CS_TRISbsf LCD_CSclrf temp_regcall Delaycall Delaycall Delaybcf LCD_RST_TRISbcf LCD_RSTcall Delaybsf LCD_RSTcall InitSPIcall InitPortA_SPIcall InitPortB_SPIbcf LCD_Ebcf LCD_RScall WritePortA;Function Setcall Delaymovlw b'00111100' ;0011NFxxmovwf temp_wrcall InitWritecall Delaymovlw b'00001100' ;Display offmovwf temp_wrcall InitWritecall Delaymovlw b'00000001' ;Display Clearmovwf temp_wrcall InitWritecall Delaymovlw b'00000110' ;Entry modemovwf temp_wrcall InitWritereturn;-------------------------------------------------------------;Function to write to the PORT;-------------------------------------------------------------InitWritebcf LCD_Ebcf LCD_RScall WritePortAcall WritePortBnopnopnopbsf LCD_Ecall WritePortAnopnopnopnopnopnopnopnopnopbcf LCD_Ecall WritePortAreturn;---------------------------------------------------;LCD busy delay;---------------------------------------------------global LCDBusyLCDBusycall SDelaycall SDelayreturnglobal ClearLCDClearLCDmovlw 0x01movwf temp_wrrcall i_writereturn;---------------------------------------------------;Write to Line1;---------------------------------------------------global LCDLine_1LCDLine_1movlw 0x80movwf temp_wrrcall i_writereturn;---------------------------------------------------;Write to Line2;---------------------------------------------------global LCDLine_2LCDLine_2movlw 0xC0movwf temp_wrrcall i_writereturn;---------------------------------------------------;Write data;---------------------------------------------------global d_writed_writercall LCDBusybcf LCD_Ebsf LCD_RScall WritePortAcall WritePortBnopnopnopnopbsf LCD_Ecall WritePortAnopnopnopnopnopnopbcf LCD_Ebcf LCD_RScall WritePortAmovf temp_wr,wmovwf TXREG ;carriage returnbtfss TXSTA,TRMT ;wait for data TXbra $-2return;---------------------------------------------------;Write instrution;---------------------------------------------------global i_writei_writebcf LCD_Ebcf LCD_RScall WritePortArcall LCDBusycall WritePortBnopnopnopnopbsf LCD_Ecall WritePortAnopnopnopnopnopnopbcf LCD_Ebcf LCD_RScall WritePortAreturn;---------------------------------------------------;Initialize MCP923S17 Port;---------------------------------------------------InitPortA_SPIbcf LCD_CSmovlw 0x40movwf SSPBUFcall Checkmovlw 0x00movwf SSPBUFcall Checkmovlw 0x00movwf SSPBUFcall Checkbsf LCD_CSreturn;---------------------------------------------------;Initialize MCP923S17 Port;---------------------------------------------------InitPortB_SPIbcf LCD_CSmovlw 0x40movwf SSPBUFcall Checkmovlw 0x01movwf SSPBUFcall Checkmovlw 0x00movwf SSPBUFcall Checkbsf LCD_CSreturn;---------------------------------------------------;Initialize SPI;---------------------------------------------------global InitSPIInitSPIbcf TRISC,5bcf TRISC,3movlw 0x22movwf SSP1CON1bsf SSP1STAT,CKEbcf PIR1,SSPIFreturnglobal CheckCheckbtfss PIR1,SSPIFgoto $-2bcf PIR1,SSPIFmovf SSPBUF,wreturn;---------------------------------------------------;Write to MCP923S17 Port;---------------------------------------------------WritePortBbcf LCD_CSmovlw 0x40movwf SSPBUFcall Checkmovlw 0x13movwf SSPBUFcall Checkmovf temp_wr,w; movlw 0xFFmovwf SSPBUFcall Checkbsf LCD_CSreturn;---------------------------------------------------;Write to MCP923S17 Port;---------------------------------------------------WritePortAbcf LCD_CSmovlw 0x40movwf SSPBUFcall Checkmovlw 0x12movwf SSPBUFcall Check; movlw 0x80; movlw 0x40; movlw 0xc0movf temp_reg,wmovwf SSPBUFcall Checkbsf LCD_CSreturnGLOBAL DelayDelaynopnopnopnopdecfsz Dreg1goto Delaydecfsz Dreg2goto DelayreturnSDelaydecfsz Dreg1goto SDelaydecfsz Dreg1goto $-2decfsz Dreg1goto $-2decfsz Dreg1goto $-2decfsz Dreg1goto $-2decfsz Dreg1goto $-2decfsz Dreg1goto $-2decfsz Dreg1goto $-2decfsz Dreg1goto $-2returngoto $END

author: Bored@Work
author_rank: Super Contributor
timestamp: April 12, 2013, 08:20:39 pm
content: QuoteBy learning the particular assembler language, the architecture of the MCU, and some basic algorithms and data structures.QuoteIts hardware interface and the protocol used to drive and communicate with it.

author: mariush
author_rank: Super Contributor
timestamp: April 12, 2013, 08:44:17 pm
content: That code you pasted is in assembler language. It's kind of hard to learn if you have no programming experience.You don't have to learn Assembler these days, although it wouldn't hurt. You can write programs directly in C and "upload" them in the microcontroller.LCD screens communicate with the microcontroller through several wires, and you send and receive digital ones and zeroes through the wires with the microcontroller.The language the LCD screen understands is explained in its datasheet - the screen has on its back a chip that has the brains to light up dots on the screen and form digits, so the microcontroller has to talk to that chip and tell it what letters to display.There's various chips on the backs of those screens but the most popular chips on the cheap displays all copy an old classic chip called HD44780.Your microcontroller sends commands to the chip on the back of the screen by sending 1s and 0s through the wires and the commands are there in the datasheet for the chip that's behind the screen or in the datasheet for the screen.Here's for example a datasheet for a 2x16 lcd screen, from page 11 it explains what each wire in the connector is and shows the commands to talk to the chip and further below there's code in C which shows how to initialize the screen and write characters on it:http://savedonthe.net/download/480/lcd_2x16.htmlIn order to understand that code or the C code, you have to understand how that microcontroller works, and for that you have to read the datasheet of that microcontroller, to understand the concepts (input output ports and so on).With Arduino it's a bit easier, because there's a library already built for you , but that basically hides things from you and you won't learn quite as much

author: andyturk
author_rank: Frequent Contributor
timestamp: April 13, 2013, 02:04:50 am
content: Quote from: tahmod on April 12, 2013, 07:24:09 pmThen find a different tutorial. Learning how to do it in assembly is ridiculous.Trythis.

author: mariush
author_rank: Super Contributor
timestamp: April 13, 2013, 02:11:20 am
content: or this:http://www.mikroe.com/chapters/view/77/pic-basic-book-chapter-4-examples/#c4v12