Está en la página 1de 14

M.

I Eduardo Ramrez Snchez

TM4C1294

TM4C1294

b0 b1

PORTA

1 b4
b7

b2

01

06
0F

28

Programa en C
Directivas del Prepocesador
- define (Macros)
- includes
Declaraciones Globales
Variables
- Funciones
main()
{
--}

Funciones Definidas por el Usuario

/*
* Este programa inicializa y despliega el mensaje HOLA
* en un LCD
*/
#define PORTADAT (*((volatile unsigned int*)0x400643FC))
#define PORTADIR (*((volatile unsigned int*)0x40064400))
#define PORTADEN (*((volatile unsigned int*)0x4006451C))
#define RCGCGPIO (*((volatile unsigned int*)0x400FE608))
#define RS 1
#define RW 2
#define EN 4
void delayMs(int n);
void delayUs(int n);
void LCD_nibble_write(unsigned char data, unsigned char control);
void LCD_command(unsigned char command);
void LCD_data(unsigned char data);
void LCD_init(void);

int main(void)
{
LCD_init();
for(;;)
{
LCD_command(1);
LCD_command(0x80);
delayMs(500);
LCD_data('H');
LCD_data('o');
LCD_data('l');
LCD_data('l');
LCD_data('a');
delayMs(500);
}
}

/*limpia display*/
/*cursor del LCD a localidad*/

void LCD_init(void)
{
RCGCGPIO = RCGCGPIO + 0x01;
PORTADIR = PORTADIR + 0Xff;
PORTADEN = PORTADEN + 0xFF;
delayMs(50);
LCD_nibble_write(0x30, 0);
delayMs(5);
LCD_nibble_write(0x30, 0);
delayUs(100);
LCD_nibble_write(0x30, 0);
delayUs(40);
LCD_nibble_write(0x20, 0); /* modo 4 bit */
delayUs(40);
LCD_command(0x28); /*4-bit de datos, 2-lineas, 5x7 */
LCD_command(0x06); /* cursor a la derecha */
LCD_command(0x01); /*limpia pantalla,cursor al inicio */
LCD_command(0x0F); /*enciende display ,cursor parpadeando*/
}

void LCD_nibble_write(unsigned char data, unsigned char control)


{
data &= 0xF0;
/* limpia el nibble bajo para control */
control &= 0x0F; /* limpia el nibble alto para dato */
PORTADAT = data | control;
/* RS = 0, R/W = 0 */
PORTADAT = data | control | EN;
/* pulso E */
delayUs(0);
PORTADAT = data;
PORTADAT = 0;
}

void LCD_command(unsigned char command)


{
LCD_nibble_write(command & 0xF0, 0); /* nibble alto primero */
LCD_nibble_write(command << 4, 0); /* luego nibble bajo */
if (command < 4)
delayMs(2);
/* comandos 1 y 2 tiempo 1.64ms */
else
delayUs(40);
/* los demas 40 us */
}
void LCD_data(unsigned char data)
{
LCD_nibble_write(data & 0xF0, RS); /* nibble alto primero */
LCD_nibble_write(data << 4, RS); /* luego nibble bajo */
delayUs(40);
}

/* retarda n milisegundos (16 MHz CPU clock) */


void delayMs(int n)
{
int i, j;
for(i = 0 ; i < n; i++)
for(j = 0; j < 3180; j++)
{}
/* no hacer nada por 1 ms */
}
/* retarda n microsegundos (16 MHz CPU clock) */
void delayUs(int n)
{
int i, j;
for(i = 0 ; i < n; i++)
for(j = 0; j < 3; j++)
{}
/* no hacer nada por 1 us */
}

También podría gustarte