#include "F28x_Project.h"
#include "common.h"
#include "extern.h"
#include "math.h"
void main(void)
{
//
// Initialize device clock and peripherals
//
InitSysCtrl();
//
// Initialize GPIO
//
InitGpio();
//
// Disable CPU interrupts
//
DINT;
//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
//
InitPieCtrl();
//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
IER = 0x0000;
IFR = 0x0000;
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
InitPieVectTable();
lcd_init();
EALLOW;
//
// Enable PIE interrupt
//
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
//
// Enable global Interrupts and higher priority real-time debug events:
//
IER |= M_INT1; // Enable group 1 interrupts
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
while(1)
{
send_string("Hello, LCD!");
DELAY_US(1000); // Delay for 1 second
}
}
void lcd_init(void)
{
GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO40 = 1;
GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO41 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO23 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO22 = 1;
// Configure LCD control pins as outputs
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // RS
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // EN
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; // RS
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; // EN
DELAY_US(15000); // 15000us...0.015 seconds
DELAY_US(4100); // 4100us
DELAY_US(100);
send_command(0x33); // 4 bit mode
send_command(0x32); // 4 bit mode
DELAY_US(4100);
send_command(0x28); // 4 bit mode
DELAY_US(40);
send_command(0x0E); // display on cursor on
DELAY_US(40);
send_command(0x01); // clear the screen
DELAY_US(40);
send_command(0x06); // increment cursor
DELAY_US(1640);
send_command(0x80); // row 1 column 1
DELAY_US(4100);
}
void send_command(unsigned char cmd)
{
GpioDataRegs.GPACLEAR.bit.GPIO1 = 1; // RS = 0 (command mode)
GpioDataRegs.GPASET.bit.GPIO0 = 1; // EN = 1 (enable high)
GpioDataRegs.GPBDAT.bit.GPIO40 = (cmd >> 4) & 0x01;
GpioDataRegs.GPADAT.bit.GPIO23 = (cmd >> 5) & 0x01;
GpioDataRegs.GPBDAT.bit.GPIO41 = (cmd >> 6) & 0x01;
GpioDataRegs.GPADAT.bit.GPIO22 = (cmd >> 7) & 0x01;
GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; // EN = 0 (enable low)
DELAY_US(2000); // Delay required for command execution
GpioDataRegs.GPASET.bit.GPIO0 = 1; // EN = 1 (enable high)
GpioDataRegs.GPBDAT.bit.GPIO40 = cmd & 0x01;
GpioDataRegs.GPADAT.bit.GPIO23 = (cmd >> 1) & 0x01;
GpioDataRegs.GPBDAT.bit.GPIO41 = (cmd >> 2) & 0x01;
GpioDataRegs.GPADAT.bit.GPIO22 = (cmd >> 3) & 0x01;
GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; // EN = 0 (enable low)
DELAY_US(2000);
}
void send_string(char *s)
{
while(*s)
{
send_data(*s);
s++;
}
}
void send_data(unsigned char data)
{
GpioDataRegs.GPASET.bit.GPIO1 = 1; // RS = 1 (Data mode)
GpioDataRegs.GPASET.bit.GPIO0 = 1; // EN = 1 (enable high)
GpioDataRegs.GPBDAT.bit.GPIO40 = (data >> 4) & 0x01;
GpioDataRegs.GPADAT.bit.GPIO23 = (data >> 5) & 0x01;
GpioDataRegs.GPBDAT.bit.GPIO41 = (data >> 6) & 0x01;
GpioDataRegs.GPADAT.bit.GPIO22 = (data >> 7) & 0x01;
GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; // EN = 0 (enable low)
DELAY_US(2000); // Delay required for command execution
GpioDataRegs.GPASET.bit.GPIO0 = 1; // EN = 1 (enable high)
GpioDataRegs.GPBDAT.bit.GPIO40 = data & 0x01;
GpioDataRegs.GPADAT.bit.GPIO23 = (data >> 1) & 0x01;
GpioDataRegs.GPBDAT.bit.GPIO41 = (data >> 2) & 0x01;
GpioDataRegs.GPADAT.bit.GPIO22 = (data >> 3) & 0x01;
GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; // EN = 0 (enable low)
DELAY_US(2000);
}