문자 처리.
문자열 처리.
하이퍼터미널로 받은값 처리.
CGRAM 사용으로 사용자 정의문자 처리.
SI로 컴파일..
전부 하나하나 함수이기때문에 갔따 쓰면된다.. 알아서 잘배끼라 ..!!
#include "project.h"
#include "AT91SAM7S256.h"
//#define _StringLCD
//#define _SerialLCD
#define _UserMode
#define PIN(num) AT91C_PIO_PA##num
#define MY_LOW (*(AT91_REG *)AT91C_PIOA_CODR)
#define MY_HIGH (*(AT91_REG *)AT91C_PIOA_SODR)
#define MY_RS PIN(8)
#define MY_RW PIN(11)
#define MY_ENB PIN(12)
#define MY_DB(num) PIN(num)
#define MAIN_OSC 18432000 // 크리스탈 속도
#define MAIN_CLK ((MAIN_OSC*73/14)/2) // 체배기를 거친 후 속도
#define DBGU_SPEED 115200 // 디버그 유닛 속도
void Reset_DBGU()
{
// Reset and disable receiver
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
// Disable interrupts
AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF;
// Configure PIOs for DBGU
AT91C_BASE_PIOA->PIO_ASR = AT91C_PA9_DRXD | AT91C_PA10_DTXD;
AT91C_BASE_PIOA->PIO_BSR = 0;
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA9_DRXD | AT91C_PA10_DTXD;
// === Configure serial link ===
// Define the baud rate divisor register [BRGR = MAIN_CLK / (115200 * 16)]
AT91C_BASE_DBGU->DBGU_BRGR = MAIN_CLK / (DBGU_SPEED * 16);
// Define the USART mode
AT91C_BASE_DBGU->DBGU_MR = AT91C_US_PAR_NONE | AT91C_US_CHMODE_NORMAL;
// Disable the RX and TX PDC transfer requests
AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_RXTDIS;
AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_TXTDIS;
// Enable transmitter
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_TXEN | AT91C_US_RXEN;
}
unsigned char DBGU_Recv_Char()
{
while (0 == (AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY));
return AT91C_BASE_DBGU->DBGU_RHR;
}
void init_LED()
{
(*(AT91_REG *)AT91C_PIOA_PER) = MY_DB(13)|MY_DB(29)|MY_DB(30);
(*(AT91_REG *)AT91C_PIOA_OER) = MY_DB(13)|MY_DB(29)|MY_DB(30);
MY_LOW = MY_DB(13)|MY_DB(30);
MY_HIGH = MY_DB(29);
}
void CharLCDEnable()
{
AT91C_BASE_PIOA->PIO_PER = PIN(0)|PIN(1)|PIN(2)|PIN(3)|PIN(4)|PIN(5)|PIN(6)|PIN(7)|PIN(8)|PIN(11)|PIN(12);
AT91C_BASE_PIOA->PIO_OER = PIN(0)|PIN(1)|PIN(2)|PIN(3)|PIN(4)|PIN(5)|PIN(6)|PIN(7)|PIN(8)|PIN(11)|PIN(12);
}
void Delay()
{
volatile unsigned int iCnt1;
for(iCnt1 = 0; iCnt1 < 10000 ; ++iCnt1);
}
void CharAllLOW()
{
MY_LOW = PIN(0)|PIN(1)|PIN(2)|PIN(3)|PIN(4)|PIN(5)|PIN(6)|PIN(7)|PIN(8)|PIN(11)|PIN(12);
}
void Start()
{
CharAllLOW();
MY_LOW = MY_RW;
Delay();
MY_HIGH = MY_ENB; //4
Delay();
}
void End()
{
Delay();
MY_LOW = MY_ENB;
Delay();
MY_HIGH = MY_ENB;
}
void ClearDisplay()
{
Start();
MY_HIGH = MY_DB(0);
End();
}
void DisplayOnOff()
{
Start();
MY_HIGH = MY_DB(2)|MY_DB(3);
End();
}
void CursorOrDisplayShift()
{
Start();
MY_HIGH =MY_DB(2)|MY_DB(3)|MY_DB(4);
End();
}
void FunctionSet()
{
Start();
MY_HIGH = MY_DB(2)|MY_DB(3)|MY_DB(4)|MY_DB(5);
End();
}
void EntryMode()
{
Start();
MY_HIGH = MY_DB(1)|MY_DB(2);
End();
}
void SetLCD()
{
FunctionSet();
DisplayOnOff();
CursorOrDisplayShift();
EntryMode();
ClearDisplay();
}
void WriteDataRam(volatile unsigned char cData)
{
CharAllLOW();
MY_HIGH = MY_RS;
MY_HIGH = MY_ENB; //4
Delay();
MY_HIGH = cData;
Delay();
MY_LOW = MY_ENB;
Delay();
MY_HIGH =MY_RW;
Delay();
}
void SetDDRamAddr(volatile unsigned int iData)
{
Start();
MY_HIGH = MY_DB(7)|iData;
End();
}
void SetCGRamAddr(volatile unsigned int iData)
{
Start();
MY_HIGH = MY_DB(6)|iData;
End();
}
void StringLCD(volatile unsigned char * cData)
{
volatile unsigned int iCnt =0;
while(*(cData + iCnt) != 0)
{
CharAllLOW();
MY_HIGH = MY_RS;
MY_HIGH = MY_ENB; //4
Delay();
MY_HIGH = *(cData+iCnt);
Delay();
MY_LOW = MY_ENB;
Delay();
MY_HIGH =MY_RW;
Delay();
iCnt++;
}
}
void SerialLCD()
{
volatile unsigned char DD;
volatile unsigned int iCnt = 0;
Reset_DBGU();
while(1)
{
DD = DBGU_Recv_Char();
if(iCnt == 17)
{
SetDDRamAddr(0x40);
}
if(iCnt == 33)
{
ClearDisplay();
iCnt = 0;
}
WriteDataRam(DD);
iCnt++;
}
}
void UserMode()
{
volatile unsigned int iCnt;
volatile unsigned int font[] = {
0x0E, 0x11, 0x11, 0x0E, 0x00, 0x00, 0x1F, 0x00,
0x09, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x09,
0x1E, 0x02, 0x02, 0x02, 0x1F, 0x04, 0x04, 0x04,
0x00, 0x00, 0x00, 0x15, 0x0A, 0x00, 0x00, 0x00};
SetCGRamAddr(0x40);
for(iCnt=0; iCnt <32; iCnt++)
{
WriteDataRam(font[iCnt]);
}
SetDDRamAddr(0x86);
WriteDataRam(0x00);
WriteDataRam(0x01);
WriteDataRam(0x02);
WriteDataRam(0x03);
}
int main()
{
init_LED(); // LED SETTING
CharLCDEnable(); // ALL LCD ENABLE
CharAllLOW(); // ALL DB LOW SETTING
SetLCD(); // LCD SETTING
#ifdef _StringLCD
StringLCD("ABCDEFG"); // STRING LCD
#endif
#ifdef _SerialLCD
SerialLCD(); // SERIAL LCD
#endif
#ifdef _UserMode
UserMode(); // USERMODE(KOREAN)
#endif
return 0;
}