This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

str912 hd44780 problem

Hello, i wanted to ask if anyone know whats wrong with this code when i want to send letters to my display with the hd44780 but it wont work it only works when its in a loop otherweise it simply wont show anything.

main.c


#include <91x_lib.H>
#include "lcd.h"



int main(void)
{
        LCD_init();
        LCD_putstring("abc");
         SCU->PRR1 |=  __GPIO7 | __GPIO3;
        SCU->PCGR1 |= __GPIO7 | __GPIO3;

        SCU->GPIOTYPE[7]=0x00;
        SCU->GPIOOUT[7]=0x5555;
        GPIO7->DDR=0xff;


        SCU->GPIOIN[3]=0x00;
        GPIO3->DDR=0;





        while(1)
        {

        //LCD_control(ON,BLINK,SHOW);
        GPIO7->DR[0xf0<<2]=~GPIO3->DR[0xf0<<2];




        }






}

lcd.h




#ifndef __LCD_H #define __LCD_H
#define BLINK 0x01 // Alias for blinking cursor #define NOBLINK 0x00 // Alias for non blinking cursor #define SHOW 0x02 // Alias for cursor on #define HIDE 0x00 // Alias for cursor off #define ON 0x04 // Alias for display on #define OFF 0x00 // Alias for display off
void LCD_init(void); void LCD_putchar(unsigned char value); void LCD_putstring(char *str); void LCD_control(unsigned char dsp,unsigned char blink,unsigned char cursor); void LCD_setpos(unsigned char p); void LCD_clear(void);
#endif

lcd.c

#include "91x_map.h"
#include "91x_scu.h"

// LCD Port access macros

#define LCD_DATA(x) { GPIO8->DR[0x3fc] = (x); };

#define CLR_E { GPIO9->DR[0x3fc] &= ~(1<<0);  }
#define SET_E { GPIO9->DR[0x3fc] |= (1<<0);  }

#define CLR_RS { GPIO9->DR[0x3fc] &= ~(1<<2);  }
#define SET_RS { GPIO9->DR[0x3fc] |= (1<<2);  }

#define CLR_RW { GPIO9->DR[0x3fc] &= ~(1<<1);  }
#define SET_RW { GPIO9->DR[0x3fc] |= (1<<1);  }

static void LCD_delay(int cycles)
{
        cycles*=50;
        while(cycles--) asm volatile ("nop");
}

static void LCD_write(unsigned char value, int command)
{
        CLR_RW;
        if(command) CLR_RS else SET_RS;

#ifdef LCD_4BIT
        LCD_DATA((value>>4)&0xf);
    SET_E;
        LCD_delay(1);
        CLR_E;

    LCD_DATA((value)&0xf);
    SET_E;
        LCD_delay(1);
        CLR_E;

#else
        LCD_DATA(value);
        SET_E;
        LCD_delay(1);
        CLR_E;
#endif

        LCD_delay(4);
}

void LCD_init()
{
// disable reset signal for GPIO ports 8 and 9
    SCU->PRR1 |= __GPIO8 | __GPIO9;

// enable peripheral clock for GPIO ports 8 and 9
    SCU->PCGR1 |= __GPIO8 | __GPIO9;

// set output type to push-pull for all port 8 lines and lines 0-2 for port 9
    SCU->GPIOTYPE[8] = 0x0000 ;
    SCU->GPIOTYPE[9] &= ~0x3f ;

// set all port 8 lines to output (both registers below need to be set for GPIO to work)
    SCU->GPIOOUT[8]  = 0x5555;
    GPIO8->DDR = 0xff;

// set port 9 lines 0..2 to output
    SCU->GPIOOUT[9]  &= ~0x3f ;
    SCU->GPIOOUT[9]  |= 0x15 ;
    GPIO9->DDR |= 0x7;


        LCD_write(0x30, 1); LCD_delay(200);
        LCD_write(0x30, 1); LCD_delay(200);
        LCD_write(0x30, 1); LCD_delay(200);

        LCD_write(0x38, 1);
        LCD_write(0x01, 1);
        LCD_write(0x06, 1);
        LCD_write(0x0c, 1);
        LCD_write(0x02, 1);
        LCD_write(0x80, 1);

        LCD_delay(100);
}

void LCD_clear()
{
        LCD_write(1, 1);
        LCD_delay(100);

}

void LCD_putchar(unsigned char value)
{
        LCD_write(value,0);
}

void LCD_putstring(char *str)
{
    while(*str)
        LCD_putchar(*str++);
}

void LCD_control(unsigned char dsp,unsigned char blink,unsigned char cursor)
{
    unsigned char control;  // variable to generate instruction byte

    control = (0x08 + blink + cursor + dsp); // Cursor control

        LCD_write(control, 1);
        LCD_delay(100);

}

void LCD_setpos(unsigned char p)
{
    LCD_write(0x80 | p, 1);
        LCD_delay(10);

}


Parents Reply Children