Author Topic: DOGM162 problems  (Read 3869 times)

0 Members and 1 Guest are viewing this topic.

Offline TheWinterSnowTopic starter

  • Contributor
  • Posts: 36
DOGM162 problems
« on: May 07, 2015, 05:56:05 am »
I purchased a DOGM162 with an Arduino Mega2560 some weeks ago.  Because I was intending to write my code in C and since no readily available libraries fore the DOGM series exist I have had to write the code on my own.  Unfortunately the code does not work, or rather, I can not get anything to display on the screen.  I am using the 8-bit communication because I have enough pins in my project and the data sheet of the device has little information about 4 bit and SPI, at the moment I am trying to explore the science of the device and get it displaying simple text.  I do not have a logic analyzer and I only have an analog O-scope so I can't see what my code is doing at the port level and I have been wrangling to get AVR studio to work because I can't get VS Shell to install (keeps giving me an error).  I have no clue what it is doing and I have no clue if my code is working or if I don't have things connected right (which I am sure I do) or if my LCD is bunk.
I would at least like to make sure my code is correct, can anyone look over it and see.  I did the initialization based on the datasheet and it is supossed to set everything up inclusing a blinking cursor then I took it further and made it add the Character 'A' to the screen.  When I plug everything up I get nothing.
 
Code: [Select]
#define F_CPU 16000000UL

#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include <inttypes.h>


uint8_t triggerHold = 10;
uint8_t E = 0x04; // enable bit mask (0000 0100) bit 2
uint8_t RS = 0x02; // RS bit mask (0000 0010) bit 1


// Generates a pulse for the enable bit
void clk(){
    PORTK ^= E; // Enable pin low
    _delay_ms(triggerHold); // Delay for some time
    PORTK ^= E; // Enable pin high
    _delay_ms(triggerHold); // Delay again for some time
}

// -----------------------------------------------------------------------------------------------

// Function to initialize DOGM162 @ 5V operation
void LCD_init(){

    /* =================
        * PORT K bit layout
        * =================
        *
        * 0000 0001 (PIN 0) = R/W
        * 0000 0010 (PIN 1) = RS
        * 0000 0100 (PIN 2) = E
        *
        */

    /* =================
        * Pin Definitions
        * =================
        *
        * R/W: Low = Write High = Read
        * RS: Low = Command High = Data
        * E: Enable (falling edge)
        *
        */

    /* =================
        * LCD Initilization
        * =================
        *
        * -----------------------------------------------------------
        * Port Initialization commands given in the DOGM162 Datasheet
        * -----------------------------------------------------------
        *
        * Port F is set to the command
        *
        * Pin 2 @ PORTK sets enable bit low, clocking the data on POTTF
        * Delay holds the enable bit low for duration 'triggerHold'
        * Pin 2 @ PORTK sets enable bit high, followed by another short delay
        * Delays poll the MPU while the LCD is executing the command
        *
        * Port F is set to next command
        * Rinse and Repeat
        *
        */

    // Function Set
    PORTF = 0x39; // PORTF = 0011 1001 (move to instruction table 1 (0,1))
    clk();

    // Bias Set
    PORTF = 0x1C; // PORTF = 0001 1100
    clk();

    // Power Control
    PORTF = 0x52; // PORTF = 0101 0010
    clk();

    // Follower Control
    PORTF = 0x69; // PORTF = 0110 1001 (follower on, amplfied ratio = x1 or unity)
    clk();

    // Contrast Set
    PORTF = 0x74; // PORTF = 0111 0100 (contrast set to 4)
    clk();;

    // Function Set
    PORTF = 0x38; // PORTF = 0011 1000 (move to instruction table 0 (0,0))
    clk();

    // Display On
    PORTF = 0x0F; // PORTF = 0000 1111 (Display on, cursor on, cursor position on)
    clk();

    // Clear Display
    PORTF = 0x01; // PORTF = 0000 0001 (Clear display)
    clk();

    // Entry Mode Set
    PORTF = 0x06; // PORTF = 0000 0110 (I/D high, increment 1 position)
    clk();

}

// -----------------------------------------------------------------------------------------------

// Writes data to LCD
void LCD_write(){

    PORTF = 0x41; // ASCII for the character 'A'
    PORTK |= RS; // Set RS high to accept data

    clk();

    PORTK &= ~RS; // Set RS low to accept commands
}


// ===============================================================================================
// ===============================================================================================

// main program
int main(void){

    // initialize ports

    //PORT F handles 8-bit data line
    //PORT K handles E, RS and R/W
    DDRK = 0xFF; // Set PORT K to output
    DDRF = 0xFF; // Set PORT F to output

    PORTF = 0x00; // Set PORTF
    PORTK = E; // Set PORTK (enable pin high)

    // initialize LCD
    LCD_init();

    // write to LCD
    LCD_write();

    // infinite loop to keep MPU going
    while(1){}

    return 0;
}

 
As you can see I like comments and it should be easily understandable.
Here is the datasheet:  http://www.lcd-module.com/eng/pdf/doma/dog-me.pdf
Any pointers would be great, thanks.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: DOGM162 problems
« Reply #1 on: May 07, 2015, 09:40:19 am »
Not used that exact display but typically you have to set it up in a different way to a 'standard' lcd as shown here.
http://www.sonsivri.to/forum/index.php?topic=11259.0

To prove your hardware works, it migh be better to first use a C++ example from the Arduino forum, searching on EADOG 162 brings up several entries.
http://forum.arduino.cc/index.php?topic=36891.0

https://www.pjrc.com/teensy/td_libs_DogLcd.html





 

Offline bobcat

  • Regular Contributor
  • *
  • Posts: 94
  • Country: us
Re: DOGM162 problems
« Reply #2 on: May 07, 2015, 10:29:50 am »
You can not use XOR to toggle the enable pin.
Quote
void clk(){
    PORTK ^= E;                  // Enable pin low
    _delay_ms(triggerHold);         // Delay for some time
    PORTK ^= E;                  // Enable pin high
    _delay_ms(triggerHold);         // Delay again for some time
}

Your function should look like this:
void clk(){
    PORTK &= ~E;                  // Enable pin low
    _delay_ms(triggerHold);         // Delay for some time
    PORTK |= E;                  // Enable pin high
    _delay_ms(triggerHold);         // Delay again for some time
}

Also the PSB, CSB, R/W, RS, and RESET pins have to connected and driven correctly. It's all there in the data sheet.
« Last Edit: May 07, 2015, 10:40:55 am by bobcat »
 

Offline TheWinterSnowTopic starter

  • Contributor
  • Posts: 36
Re: DOGM162 problems
« Reply #3 on: May 08, 2015, 01:20:11 am »
Yeah, I knew that either method would work, but it is probably better off leaving the enable low and setting/resetting instead of toggling.

PSB, CSB RS and R/W were all properly hardwired to either 5v or GND based on the configuration.

I moved over the the arduino platform and used a DogLcd library and it still isn't doing anything to the screen, so now I think I am troubleshooting if I have a dead LCD.  I am making a shield for it to make sure I have solid connections.  Did a quick PCB for it and already sent it off the the fab, will have to keep my fingers crossed.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: DOGM162 problems
« Reply #4 on: May 08, 2015, 11:12:03 am »
Found my old Dog 163 display, previously used with a Pic,  and followed the Arduino wiring and software from this site, all works well, with either the 162 or 163 software.

RS is controlled by the software.

https://code.google.com/p/doglcd/

 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 2069
  • Country: us
    • netstuff
Re: DOGM162 problems
« Reply #5 on: May 08, 2015, 05:30:27 pm »
I bought some of those 'display on glass module' (that's what DOGM stands for, btw):



I got mine to work but it was a long time ago.  the teensy guy (paul) does have a library for it.

I would not use all the wires I used (go for serial or 4bit at most) but the displays are actually kind of nice.

if you can't get yours working, I may be able to find my old displays and try them again.  it would be arduino based, though.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf