<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic LCD timing issue? in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/LCD-timing-issue/m-p/123830#M21</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #ff0000;"&gt;This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="postdetails"&gt;&lt;STRONG&gt;Posted: Fri Dec 10, 2004 1:13 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;Hi Folks&lt;BR /&gt;&lt;BR /&gt; I am trying to use 2 x 40 character LCD with HC908GP32 running with a 32.768kHz crystal.&lt;BR /&gt;&lt;BR /&gt; The code below (in assembler) work fine in monitor mode, but, not when programmed into the micro.&lt;BR /&gt;&lt;BR /&gt; I would like to use the busy flag from the LCD so that the code is faster and looks neater.&lt;BR /&gt;&lt;BR /&gt; If anyone has any ideas I would like to hear them.&lt;BR /&gt;&lt;BR /&gt; Note that I am only using Port C with an LED to try to work out where the program actually gets to.&lt;BR /&gt;&lt;BR /&gt; When programmed, it looks like that LCD powers up correctly, then nothing.&lt;BR /&gt;&lt;BR /&gt; Have fun&lt;BR /&gt;&lt;BR /&gt; $BASE 10T ; sets number base to 10 unless otherwise specified.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;SPAN class="postbody"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color: #000000;"&gt;; Setting labels for the ports&lt;BR /&gt; PORTA EQU $0000 ; address of PORTA&lt;BR /&gt; PORTB EQU $0001 ; address of PORTB&lt;BR /&gt; PORTC EQU $0002 ; address of PORTC&lt;BR /&gt; PORTD EQU $0003 ; address of PORTD&lt;BR /&gt; PORTE EQU $0008 ; address of PORTE&lt;BR /&gt; DDRA EQU $0004 ; data direction control for PORTA&lt;BR /&gt; DDRB EQU $0005 ; data direction control for PORTB&lt;BR /&gt; DDRC EQU $0006 ; data direction control for PORTC&lt;BR /&gt; DDRD EQU $0007 ; data direction control for PORTD&lt;BR /&gt; DDRE EQU $000C ; data direction control for PORTE&lt;BR /&gt; PTAPUE EQU $000D ; Pullup enable register for PORTA&lt;BR /&gt; ;PTBPUE Pullup enable register for PORTB does not exist&lt;BR /&gt; PTCPUE EQU $000E ; Pullup enable register for PORTC&lt;BR /&gt; PTDPUE EQU $000F ; Pullup enable register for PORTD&lt;BR /&gt; ;PTEPUE Pullup enable register for PORTE does not exist&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; CONFIG1 EQU $1F ; Configuration register address for COP etc&lt;BR /&gt;&lt;BR /&gt; ; Setting the labels for the clock speed of the chip&lt;BR /&gt; PCTL EQU $36 ; PLL control register&lt;BR /&gt; PBWC EQU $37 ; PLL bandwidth control register&lt;BR /&gt; PMSH EQU $38 ; PLL multiplier select register high&lt;BR /&gt; PMSL EQU $39 ; PLL multiplier select register low&lt;BR /&gt; PMRS EQU $3A ; PLL VCO range select register&lt;BR /&gt; PMDS EQU $3B ; PLL reference divider select register&lt;BR /&gt; ; ******&lt;BR /&gt;&lt;BR /&gt; ; Setting other register labels&lt;BR /&gt; TBCR EQU $001C ; Timebase Control Register&lt;BR /&gt;&lt;BR /&gt; ADSCR EQU $3C ; A/D Converter Status Control Register&lt;BR /&gt; ADR EQU $3D ; A/D data Register&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; ; Uses PORT A data lines for the LCD and PORT E for control lines.&lt;BR /&gt; ; R/W is on PORT D (0-write to, 1-read from LCD)&lt;BR /&gt;&lt;BR /&gt; ; PORT E&lt;BR /&gt; ; Bit 0 will be the Enable line&lt;BR /&gt; ; Bit 1 will be the RS (register select) line&lt;BR /&gt; ; ie data (1) or function (0) mode&lt;BR /&gt;&lt;BR /&gt; LCD EQU $0000 ; For sending info to LCD, actually PORT A&lt;BR /&gt;&lt;BR /&gt; LCD_CONTROL EQU $0008 ; PORT E, controls LCD, the following values are sent here to&lt;BR /&gt; ; operate LCD.&lt;BR /&gt; LCD_D_ON EQU %00000011 ; Sets PORT A value as character for LCD.&lt;BR /&gt; LCD_D_OFF EQU %00000010 ; Sends PORT A value as character to LCD.&lt;BR /&gt; LCD_F_ON EQU %00000001 ; Sets PORT A value as function command for LCD.&lt;BR /&gt; LCD_F_OFF EQU %00000000 ; Sends PORT A value as function command to LCD.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; org $FFFE ; Sets the reset vector for programmed chip&lt;BR /&gt; FDB INIT&lt;BR /&gt;&lt;BR /&gt; org $9000 ; program loads into memory from location specified&lt;BR /&gt;&lt;BR /&gt; INIT LDA #$00 ; Simply initialisation values&lt;BR /&gt; LDX #$00&lt;BR /&gt;&lt;BR /&gt; MOV #$31,CONFIG1 ; MCU runs w/o LVI and COP support&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; LCD_SETUP&lt;BR /&gt;&lt;BR /&gt; MOV #$FF,DDRA ; Set PORTA as output&lt;BR /&gt; MOV #$FF,DDRC ; Set PORTC as output&lt;BR /&gt; MOV #$FF,DDRD ; Set PORTD as output&lt;BR /&gt; MOV #$03,DDRE ; Set PORT E as output (3 because there are only 2 bits).&lt;BR /&gt;&lt;BR /&gt; MOV #$00,PORTC&lt;BR /&gt; MOV #$00,PORTD&lt;BR /&gt;&lt;BR /&gt; LDA #$00&lt;BR /&gt; LOOP1 LDX #$00&lt;BR /&gt; DBNZX *&lt;BR /&gt; COM PORTC&lt;BR /&gt; DBNZA LOOP1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; ; IMPORTANT to set LCD as 4 bit, must send ONLY control code '0010' on the 4 data lines,&lt;BR /&gt; ; THEN start sending the full 8 bit data/control codes in 2x4 bit nibbles, high nibble first!!!&lt;BR /&gt;&lt;BR /&gt; MOV #$20,LCD ; Sets LCD to 4 bit data&lt;BR /&gt; MOV #LCD_F_ON,LCD_CONTROL ; Do NOT use the sub routine LCD_FUNCTION here,&lt;BR /&gt; NOP ; as it will send 2x4 bit nibbles.&lt;BR /&gt; MOV #LCD_F_OFF,LCD_CONTROL&lt;BR /&gt;&lt;BR /&gt; LDA #$00&lt;BR /&gt; LOOP2 LDX #$00&lt;BR /&gt; DBNZX *&lt;BR /&gt; COM PORTC&lt;BR /&gt; DBNZA LOOP2&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; MOV #$28,LCD ; Sets display as 4 bit data, 2 line, 5x7 matrix&lt;BR /&gt; ;JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; LDA #$00&lt;BR /&gt; LOOP3 LDX #$00&lt;BR /&gt; DBNZX *&lt;BR /&gt; COM PORTC&lt;BR /&gt; DBNZA LOOP3&lt;BR /&gt;&lt;BR /&gt; MOV #$01,LCD ; Clears display and sends cursor home&lt;BR /&gt; JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; MOV #$02,LCD ; Sends cursor and display home&lt;BR /&gt; JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; MOV #$0F,LCD ; Turns display ON, cursor ON, Blink ON.&lt;BR /&gt; JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; LDHX #LCD_OK ; Load HX regs with location of message&lt;BR /&gt; LDA #'^' ; Load A with ascii value of '^'&lt;BR /&gt;&lt;BR /&gt; TEXT_1 MOV X+,LCD ; Copy the contents of location HX to LCD (PORT A). Note, also increments X.&lt;BR /&gt; CMP LCD ; Compare LCD with A&lt;BR /&gt; BEQ END_LCD_SETUP ; Exits text routine if reach end-of-text marker '^'&lt;BR /&gt; JSR LCD_DATA ; Puts text onto LCD screen&lt;BR /&gt; JMP TEXT_1&lt;BR /&gt;&lt;BR /&gt; END_LCD_SETUP&lt;BR /&gt;&lt;BR /&gt; JMP *&lt;BR /&gt;&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; LCD_FUNCTION&lt;BR /&gt; LDA LCD&lt;BR /&gt;&lt;BR /&gt; STA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_F_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_F_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; NSA ; nibble swaps the accumulator&lt;BR /&gt;&lt;BR /&gt; STA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_F_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_F_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; RTS&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; LCD_DATA&lt;BR /&gt; PSHA&lt;BR /&gt;&lt;BR /&gt; LDA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_D_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_D_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; NSA ; nibble swaps the accumulator&lt;BR /&gt;&lt;BR /&gt; STA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_D_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_D_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; PULA&lt;BR /&gt;&lt;BR /&gt; RTS&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; LCD_DELAY&lt;BR /&gt; MOV #$00,DDRA ; Set PORT A as input&lt;BR /&gt; MOV #$FF,PORTD ; Sets LCD to read mode&lt;BR /&gt; BRSET 7,PORTA,*&lt;BR /&gt; MOV #$00,PORTD ; Sets LCD to write mode&lt;BR /&gt; MOV #$FF,DDRA ; Set PORTA to output&lt;BR /&gt;&lt;BR /&gt; RTS&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; Org $8000&lt;BR /&gt; LCD_OK EQU $8000&lt;BR /&gt; DB '&amp;lt;LCD OK&amp;gt;^'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="postdetails"&gt;&lt;STRONG&gt;Posted: Sun Dec 12, 2004 10:30 pm&lt;/STRONG&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;Not to sure but don't you need to reset the stack pointer.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postbody"&gt;&lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Mon Dec 13, 2004 8:18 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;am reasonably sure that the stack pointer does not need initilizing and as I only do one set of push/pulls, reseting the stack pointer should not be an issue.&lt;BR /&gt;&lt;BR /&gt; Regardless, the program works with a timed LCD_DELAY and the same push/pulls.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;A href="http://www.freegeeks.net/modules/Forums/images/smiles/icon_sad.gif"&gt;&lt;IMG alt="Sad" border="0" src="http://www.freegeeks.net/modules/Forums/images/smiles/icon_sad.gif" /&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Mon Dec 13, 2004 7:13 pm&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt; What's your configuration (ports level + XTAL) in Monitor mode ?&lt;BR /&gt;&lt;BR /&gt; Cheers&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Fri Dec 17, 2004 11:16 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postbody"&gt;&lt;SPAN style="color: #000000;"&gt;Helllo,&lt;BR /&gt;&lt;BR /&gt; in your delay routine you have to togggle the ECLK Pin everytime you read the dataport to get actual data. So you have to use a loop ta wait until D7 is cleared.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; LCD_DELAY&lt;BR /&gt; MOV #$00,DDRA ; Set PORT A as input&lt;BR /&gt; MOV #$FF,PORTD ; Sets LCD to read mode&lt;BR /&gt; ---&amp;gt; toggle ECLK here&lt;BR /&gt; BRSET 7,PORTA,* and go back to LCD_DELAY to read again&lt;BR /&gt; MOV #$00,PORTD ; Sets LCD to write mode&lt;BR /&gt; MOV #$FF,DDRA ; Set PORTA to output&lt;BR /&gt;&lt;BR /&gt; RTS&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Thu Apr 07, 2005 6:58 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postbody"&gt;&lt;SPAN style="color: #000000;"&gt;Thanks for the help folks, it works wonderfully now.&lt;BR /&gt;&lt;BR /&gt; I finally found the time to sit down and work through it all. There were a pile of things that just weren't quite right, mostly with the way I was thinking about it.&lt;BR /&gt;&lt;BR /&gt; Have fun&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;P&gt;Message Edited by RChapman on &lt;SPAN class="date_text"&gt;01-19-2006&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;04:47 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Jan 2006 06:44:38 GMT</pubDate>
    <dc:creator>RChapman</dc:creator>
    <dc:date>2006-01-20T06:44:38Z</dc:date>
    <item>
      <title>LCD timing issue?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/LCD-timing-issue/m-p/123830#M21</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #ff0000;"&gt;This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="postdetails"&gt;&lt;STRONG&gt;Posted: Fri Dec 10, 2004 1:13 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;Hi Folks&lt;BR /&gt;&lt;BR /&gt; I am trying to use 2 x 40 character LCD with HC908GP32 running with a 32.768kHz crystal.&lt;BR /&gt;&lt;BR /&gt; The code below (in assembler) work fine in monitor mode, but, not when programmed into the micro.&lt;BR /&gt;&lt;BR /&gt; I would like to use the busy flag from the LCD so that the code is faster and looks neater.&lt;BR /&gt;&lt;BR /&gt; If anyone has any ideas I would like to hear them.&lt;BR /&gt;&lt;BR /&gt; Note that I am only using Port C with an LED to try to work out where the program actually gets to.&lt;BR /&gt;&lt;BR /&gt; When programmed, it looks like that LCD powers up correctly, then nothing.&lt;BR /&gt;&lt;BR /&gt; Have fun&lt;BR /&gt;&lt;BR /&gt; $BASE 10T ; sets number base to 10 unless otherwise specified.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;SPAN class="postbody"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color: #000000;"&gt;; Setting labels for the ports&lt;BR /&gt; PORTA EQU $0000 ; address of PORTA&lt;BR /&gt; PORTB EQU $0001 ; address of PORTB&lt;BR /&gt; PORTC EQU $0002 ; address of PORTC&lt;BR /&gt; PORTD EQU $0003 ; address of PORTD&lt;BR /&gt; PORTE EQU $0008 ; address of PORTE&lt;BR /&gt; DDRA EQU $0004 ; data direction control for PORTA&lt;BR /&gt; DDRB EQU $0005 ; data direction control for PORTB&lt;BR /&gt; DDRC EQU $0006 ; data direction control for PORTC&lt;BR /&gt; DDRD EQU $0007 ; data direction control for PORTD&lt;BR /&gt; DDRE EQU $000C ; data direction control for PORTE&lt;BR /&gt; PTAPUE EQU $000D ; Pullup enable register for PORTA&lt;BR /&gt; ;PTBPUE Pullup enable register for PORTB does not exist&lt;BR /&gt; PTCPUE EQU $000E ; Pullup enable register for PORTC&lt;BR /&gt; PTDPUE EQU $000F ; Pullup enable register for PORTD&lt;BR /&gt; ;PTEPUE Pullup enable register for PORTE does not exist&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; CONFIG1 EQU $1F ; Configuration register address for COP etc&lt;BR /&gt;&lt;BR /&gt; ; Setting the labels for the clock speed of the chip&lt;BR /&gt; PCTL EQU $36 ; PLL control register&lt;BR /&gt; PBWC EQU $37 ; PLL bandwidth control register&lt;BR /&gt; PMSH EQU $38 ; PLL multiplier select register high&lt;BR /&gt; PMSL EQU $39 ; PLL multiplier select register low&lt;BR /&gt; PMRS EQU $3A ; PLL VCO range select register&lt;BR /&gt; PMDS EQU $3B ; PLL reference divider select register&lt;BR /&gt; ; ******&lt;BR /&gt;&lt;BR /&gt; ; Setting other register labels&lt;BR /&gt; TBCR EQU $001C ; Timebase Control Register&lt;BR /&gt;&lt;BR /&gt; ADSCR EQU $3C ; A/D Converter Status Control Register&lt;BR /&gt; ADR EQU $3D ; A/D data Register&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; ; Uses PORT A data lines for the LCD and PORT E for control lines.&lt;BR /&gt; ; R/W is on PORT D (0-write to, 1-read from LCD)&lt;BR /&gt;&lt;BR /&gt; ; PORT E&lt;BR /&gt; ; Bit 0 will be the Enable line&lt;BR /&gt; ; Bit 1 will be the RS (register select) line&lt;BR /&gt; ; ie data (1) or function (0) mode&lt;BR /&gt;&lt;BR /&gt; LCD EQU $0000 ; For sending info to LCD, actually PORT A&lt;BR /&gt;&lt;BR /&gt; LCD_CONTROL EQU $0008 ; PORT E, controls LCD, the following values are sent here to&lt;BR /&gt; ; operate LCD.&lt;BR /&gt; LCD_D_ON EQU %00000011 ; Sets PORT A value as character for LCD.&lt;BR /&gt; LCD_D_OFF EQU %00000010 ; Sends PORT A value as character to LCD.&lt;BR /&gt; LCD_F_ON EQU %00000001 ; Sets PORT A value as function command for LCD.&lt;BR /&gt; LCD_F_OFF EQU %00000000 ; Sends PORT A value as function command to LCD.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; org $FFFE ; Sets the reset vector for programmed chip&lt;BR /&gt; FDB INIT&lt;BR /&gt;&lt;BR /&gt; org $9000 ; program loads into memory from location specified&lt;BR /&gt;&lt;BR /&gt; INIT LDA #$00 ; Simply initialisation values&lt;BR /&gt; LDX #$00&lt;BR /&gt;&lt;BR /&gt; MOV #$31,CONFIG1 ; MCU runs w/o LVI and COP support&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; LCD_SETUP&lt;BR /&gt;&lt;BR /&gt; MOV #$FF,DDRA ; Set PORTA as output&lt;BR /&gt; MOV #$FF,DDRC ; Set PORTC as output&lt;BR /&gt; MOV #$FF,DDRD ; Set PORTD as output&lt;BR /&gt; MOV #$03,DDRE ; Set PORT E as output (3 because there are only 2 bits).&lt;BR /&gt;&lt;BR /&gt; MOV #$00,PORTC&lt;BR /&gt; MOV #$00,PORTD&lt;BR /&gt;&lt;BR /&gt; LDA #$00&lt;BR /&gt; LOOP1 LDX #$00&lt;BR /&gt; DBNZX *&lt;BR /&gt; COM PORTC&lt;BR /&gt; DBNZA LOOP1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; ; IMPORTANT to set LCD as 4 bit, must send ONLY control code '0010' on the 4 data lines,&lt;BR /&gt; ; THEN start sending the full 8 bit data/control codes in 2x4 bit nibbles, high nibble first!!!&lt;BR /&gt;&lt;BR /&gt; MOV #$20,LCD ; Sets LCD to 4 bit data&lt;BR /&gt; MOV #LCD_F_ON,LCD_CONTROL ; Do NOT use the sub routine LCD_FUNCTION here,&lt;BR /&gt; NOP ; as it will send 2x4 bit nibbles.&lt;BR /&gt; MOV #LCD_F_OFF,LCD_CONTROL&lt;BR /&gt;&lt;BR /&gt; LDA #$00&lt;BR /&gt; LOOP2 LDX #$00&lt;BR /&gt; DBNZX *&lt;BR /&gt; COM PORTC&lt;BR /&gt; DBNZA LOOP2&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; MOV #$28,LCD ; Sets display as 4 bit data, 2 line, 5x7 matrix&lt;BR /&gt; ;JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; LDA #$00&lt;BR /&gt; LOOP3 LDX #$00&lt;BR /&gt; DBNZX *&lt;BR /&gt; COM PORTC&lt;BR /&gt; DBNZA LOOP3&lt;BR /&gt;&lt;BR /&gt; MOV #$01,LCD ; Clears display and sends cursor home&lt;BR /&gt; JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; MOV #$02,LCD ; Sends cursor and display home&lt;BR /&gt; JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; MOV #$0F,LCD ; Turns display ON, cursor ON, Blink ON.&lt;BR /&gt; JSR LCD_FUNCTION&lt;BR /&gt;&lt;BR /&gt; LDHX #LCD_OK ; Load HX regs with location of message&lt;BR /&gt; LDA #'^' ; Load A with ascii value of '^'&lt;BR /&gt;&lt;BR /&gt; TEXT_1 MOV X+,LCD ; Copy the contents of location HX to LCD (PORT A). Note, also increments X.&lt;BR /&gt; CMP LCD ; Compare LCD with A&lt;BR /&gt; BEQ END_LCD_SETUP ; Exits text routine if reach end-of-text marker '^'&lt;BR /&gt; JSR LCD_DATA ; Puts text onto LCD screen&lt;BR /&gt; JMP TEXT_1&lt;BR /&gt;&lt;BR /&gt; END_LCD_SETUP&lt;BR /&gt;&lt;BR /&gt; JMP *&lt;BR /&gt;&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; LCD_FUNCTION&lt;BR /&gt; LDA LCD&lt;BR /&gt;&lt;BR /&gt; STA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_F_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_F_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; NSA ; nibble swaps the accumulator&lt;BR /&gt;&lt;BR /&gt; STA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_F_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_F_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; RTS&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; LCD_DATA&lt;BR /&gt; PSHA&lt;BR /&gt;&lt;BR /&gt; LDA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_D_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_D_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; NSA ; nibble swaps the accumulator&lt;BR /&gt;&lt;BR /&gt; STA LCD ; Moves accumulator to location LCD, loads high 4 bits into the LCD screen&lt;BR /&gt; MOV #LCD_D_ON,LCD_CONTROL&lt;BR /&gt; NOP&lt;BR /&gt; MOV #LCD_D_OFF,LCD_CONTROL&lt;BR /&gt; JSR LCD_DELAY&lt;BR /&gt;&lt;BR /&gt; PULA&lt;BR /&gt;&lt;BR /&gt; RTS&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; LCD_DELAY&lt;BR /&gt; MOV #$00,DDRA ; Set PORT A as input&lt;BR /&gt; MOV #$FF,PORTD ; Sets LCD to read mode&lt;BR /&gt; BRSET 7,PORTA,*&lt;BR /&gt; MOV #$00,PORTD ; Sets LCD to write mode&lt;BR /&gt; MOV #$FF,DDRA ; Set PORTA to output&lt;BR /&gt;&lt;BR /&gt; RTS&lt;BR /&gt; ;*******&lt;BR /&gt;&lt;BR /&gt; Org $8000&lt;BR /&gt; LCD_OK EQU $8000&lt;BR /&gt; DB '&amp;lt;LCD OK&amp;gt;^'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="postdetails"&gt;&lt;STRONG&gt;Posted: Sun Dec 12, 2004 10:30 pm&lt;/STRONG&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;Not to sure but don't you need to reset the stack pointer.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postbody"&gt;&lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Mon Dec 13, 2004 8:18 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;am reasonably sure that the stack pointer does not need initilizing and as I only do one set of push/pulls, reseting the stack pointer should not be an issue.&lt;BR /&gt;&lt;BR /&gt; Regardless, the program works with a timed LCD_DELAY and the same push/pulls.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;A href="http://www.freegeeks.net/modules/Forums/images/smiles/icon_sad.gif"&gt;&lt;IMG alt="Sad" border="0" src="http://www.freegeeks.net/modules/Forums/images/smiles/icon_sad.gif" /&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Mon Dec 13, 2004 7:13 pm&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN style=": ; color: #000000;"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt; What's your configuration (ports level + XTAL) in Monitor mode ?&lt;BR /&gt;&lt;BR /&gt; Cheers&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Fri Dec 17, 2004 11:16 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postbody"&gt;&lt;SPAN style="color: #000000;"&gt;Helllo,&lt;BR /&gt;&lt;BR /&gt; in your delay routine you have to togggle the ECLK Pin everytime you read the dataport to get actual data. So you have to use a loop ta wait until D7 is cleared.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; LCD_DELAY&lt;BR /&gt; MOV #$00,DDRA ; Set PORT A as input&lt;BR /&gt; MOV #$FF,PORTD ; Sets LCD to read mode&lt;BR /&gt; ---&amp;gt; toggle ECLK here&lt;BR /&gt; BRSET 7,PORTA,* and go back to LCD_DELAY to read again&lt;BR /&gt; MOV #$00,PORTD ; Sets LCD to write mode&lt;BR /&gt; MOV #$FF,DDRA ; Set PORTA to output&lt;BR /&gt;&lt;BR /&gt; RTS&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN style=": ; color: #000000;"&gt;&lt;STRONG&gt;Posted: Thu Apr 07, 2005 6:58 am&lt;/STRONG&gt;&lt;SPAN class="gen"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #ff0000;"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postdetails"&gt;&lt;SPAN class="postbody"&gt;&lt;SPAN style="color: #000000;"&gt;Thanks for the help folks, it works wonderfully now.&lt;BR /&gt;&lt;BR /&gt; I finally found the time to sit down and work through it all. There were a pile of things that just weren't quite right, mostly with the way I was thinking about it.&lt;BR /&gt;&lt;BR /&gt; Have fun&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;P&gt;Message Edited by RChapman on &lt;SPAN class="date_text"&gt;01-19-2006&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;04:47 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jan 2006 06:44:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/LCD-timing-issue/m-p/123830#M21</guid>
      <dc:creator>RChapman</dc:creator>
      <dc:date>2006-01-20T06:44:38Z</dc:date>
    </item>
  </channel>
</rss>

