LCD con atmega 32 en protues

0

Esteproyectonofuncionaenlasimulación"Proteus", pero sí en el kit. No sé cuál es el problema, ¡¡aunque funciona de verdad!

/*includes*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

void EF_void_LCD_send_char(char Value );
void EF_void_LCD_send_command(char cmnd);
void EF_void_LCD_send_data(char data);
void EF_void_LCD_goto(char y, char x);
void EF_void_LCD_Clear_Screen(void);
void EF_void_LCD_print(char *string);

#define LCD_RS_PIN        5
#define LCD_RW_PIN        6
#define LCD_ENABLE_PIN    7

/*Global variables*/
int main(void){
    /*Local variables*/

    /*Initialization*/
    DDRC |= (1 << LCD_RS_PIN | 1 << LCD_RW_PIN | 1 << LCD_ENABLE_PIN);  /* Init Control PIN as Output */
    PORTC = 0x00;
    DDRB  = 0xF0;   /* Init Data PIN as Output 4,5,6,7 */
    PORTB = 0x00;
    _delay_ms(10);
    EF_void_LCD_send_command(0x28);            /* Command ..0x28---> 4-bit mode - 2 line - 5x7 font */
    EF_void_LCD_send_command(0x0C);            /* Command ..0x0C---> Display no cursor - no blink */
    EF_void_LCD_send_command(0x06);            /* Command ..0x06---> Automatic Increment - No Display shift */
    EF_void_LCD_send_command(0x80);            /* Command ..0x80---> to go to first line and 0th position in LCD */
    _delay_ms(20);

    sei();          /*Enable interrupts*/
    while(1){
        /*Call Application*/
           EF_void_LCD_goto(1, 2);
            EF_void_LCD_print("** WELCOME **");
            EF_void_LCD_goto(2, 1);
            EF_void_LCD_print("- Hello -");

    }
    return 0;
}

void EF_void_LCD_send_char(char Value ){
    /* output high nibble first */
    PORTB = (Value&0xF0);
    PORTC |= (1<<LCD_ENABLE_PIN);
    _delay_us(2);
    PORTC &= ~(1<<LCD_ENABLE_PIN);
    /* output low nibble */
    PORTB = ((Value << 4)&0xF0);
    PORTC |= (1<<LCD_ENABLE_PIN);
    _delay_us(2);
    PORTC &= ~(1<<LCD_ENABLE_PIN);
    _delay_us(100);

}
void EF_void_LCD_send_command(char cmnd){

    /*RS and RW will be LOW */
    PORTC &= ~(1<<LCD_RW_PIN);
    PORTC &= ~(1<<LCD_RS_PIN);
    EF_void_LCD_send_char(cmnd);
}

void EF_void_LCD_send_data(char data){
    PORTC &= ~(1<<LCD_RW_PIN);
    PORTC |= (1<<LCD_RS_PIN);
    EF_void_LCD_send_char(data);
}

void EF_void_LCD_goto(char y, char x)
{
    char firstAddress[] = {0x80,0xC0,0x94,0xD4};

    EF_void_LCD_send_command(firstAddress[y-1] + x-1);
    _delay_ms(10);
}

void EF_void_LCD_Clear_Screen(void)
{
    EF_void_LCD_send_command(1);      /* Clear CMD 0x01 */
    _delay_ms(10);
}

void EF_void_LCD_print(char *string)
{
    int i = 0;

    while(string[i]!=0)
    {
        EF_void_LCD_send_data(string[i]);
        i++;
    }
}
    
pregunta Shaymaa Badr

0 respuestas

Lea otras preguntas en las etiquetas