#define PIOA_PER (*(volatile unsigned int *)0xFFFFF400) // Pin enable
#define PIOA_OER (*(volatile unsigned int *)0xFFFFF410) // output enable
#define PIOA_PPUDR (*(volatile unsigned int *)0xFFFFF460)
// pull-up resistance disable
#define PIOA_CODR (*(volatile unsigned int *)0xFFFFF434)
// 대입하면 0 - clear ouput data
#define PIOA_SODR (*(volatile unsigned int *)0xFFFFF430)
// 대입하면 1 - set output data
#define CLCD_RS (1 << 8) // 0x100 (PA8)
#define CLCD_RW (1 << 9) // 0x200 (PA9)
#define CLCD_EN (1 << 10) // 0x400 (PA10)
#define CLCD_BS (0xFF << 16) // FF0000 (PA16~23)
#define CLCD_INST_CD (0x01 << 16) //Clear Display
#define CLCD_INST_FS (0x38 << 16) //Function Set(0011 1000)
#define CLCD_INST_EM (0x06 << 16) //Entry Mode(0000 0110)
#define CLCD_INST_DO (0x0F << 16) //Display ON/OFF(0000 1111)
#define CLCD_INST_CS (0x14 << 16) //Cusor Shift(0001 0100)
#define CLCD_INST_DD (0x80 << 16) //DDRAM(1000 0000)
#define CLCD_INST_RH (0x02 << 16) //Return Home(0000 0010)
#define CLCD_INST_SCG (0x40 << 16)
#define CLCD_DELAY(Z) for(iCount = 0; iCount < (Z);++iCount) // 매크로 함수
static volatile unsigned int iCount = 0;
/* 함수 선언 */
void LCD_INIT(void);
void LCD_INST(unsigned int uiInst);
void LCD_DATA(unsigned int uiData);
void write_CG_ROM(void);
int main(void)
{
LCD_INIT(); // LCD 초기화
CLCD_DELAY(70000);
// clear display
LCD_INST(CLCD_INST_FS); // Function set
CLCD_DELAY(1000);
LCD_INST(CLCD_INST_EM); // Entry Mode
LCD_INST(CLCD_INST_CS); // Cursor Shift
LCD_INST(CLCD_INST_DO); // Display ON
LCD_INST(CLCD_INST_CD); // Clear display
CLCD_DELAY(10000);
//LCD_INST(CLCD_INST_DD); // DDRAM
//LCD_INST(CLCD_INST_RH); // Return Home
write_CG_ROM();
LCD_INST(CLCD_INST_RH);
LCD_INST(CLCD_INST_DD); // DDRAM
CLCD_DELAY(10000);
LCD_DATA(0x00<<16); // 1칸
LCD_DATA(0x01<<16); // 2칸
LCD_DATA(0x02<<16); // 3칸
LCD_DATA(0x03<<16); // 4칸
LCD_DATA(0x04<<16); // 5칸
while(1);
return 0;
}
void LCD_INST(unsigned int uiInst)
{
//static volatile unsigned int iCount = 0;
// 자주 사용될 수 있으므로 static을 붙인다.
// unsigned가 더 빠르다.(CPU는 음수 처리가 느리다.)
// clear display
PIOA_CODR = CLCD_EN; // LCD 비활성화
PIOA_CODR = CLCD_RS; // instruction register select - 0으로 만든다.
PIOA_CODR = CLCD_RW; // write 모드로 만든다.
// CLCD_DELAY(4000); // tAs
PIOA_SODR = CLCD_EN; // LCD 활성화
// CLCD_DELAY(8000); //tEr
PIOA_SODR = uiInst; // 명령어를 계속 주어야 한다.
CLCD_DELAY(1); // tpsw
PIOA_CODR = CLCD_EN; // 다시 LCD 비활성화
CLCD_DELAY(82);//tH
PIOA_CODR = (0xFF << 16); // BUS 초기화
}
void LCD_DATA(unsigned int uiData)
{
//static volatile unsigned int iCount = 0; // 자주 사용될 수 있으므로 static을 붙인다.
// unsigned가 더 빠르다.(CPU는 음수 처리가 느리다.)
// clear display
PIOA_CODR = CLCD_EN; // LCD 비활성화
PIOA_SODR = CLCD_RS; // DATA register mode로 만든다.
PIOA_CODR = CLCD_RW; // write 모드로 만든다.
// CLCD_DELAY(4000); // tAs
PIOA_SODR = CLCD_EN; // LCD 활성화
// CLCD_DELAY(8000); //tEr
PIOA_SODR = uiData; // 화면을 지우는 명령
CLCD_DELAY(1); // tpsw
PIOA_CODR = CLCD_EN; // 다시 LCD 비활성화
CLCD_DELAY(82); // tH
PIOA_CODR = (0xFF << 16); // BUS 초기화
}
void LCD_INIT(void)
{
// Configure the pin in output
PIOA_OER = CLCD_BS | CLCD_RS | CLCD_RW | CLCD_EN; // 11가닥의 선이 활성화(PIN을 출력용으로)
// Set the PIO controller in PIO mode instead of peripheral mode
PIOA_PER = CLCD_BS | CLCD_RS | CLCD_RW | CLCD_EN; // PIN enable
// Disable pull-up
PIOA_PPUDR = CLCD_BS | CLCD_RS | CLCD_RW | CLCD_EN; // 해당하는 PIN을 0으로 만든다.
PIOA_CODR = (0xFF << 16);
}
void write_CG_ROM(void)
{
unsigned char i;
unsigned char cg_data[40]={
0x00, 0x0a, 0x1b, 0x1f, 0x1f, 0x0e, 0x04, 0x00, //♥
0x0e, 0x11, 0x0e, 0x00, 0x1f, 0x0a, 0x10, 0x1f, //윤
0x1d, 0x15, 0x15, 0x15, 0x1d, 0x00, 0x10, 0x1f, //민
0x09, 0x15, 0x17, 0x15, 0x15, 0x00, 0x1f, 0x01, //석
0x00, 0x0a, 0x1b, 0x1f, 0x1f, 0x0e, 0x04, 0x00 //♥
};
LCD_INST(CLCD_INST_SCG); //CG ROM 시작번지
for(i=0; i<40; i++)
{
LCD_DATA(cg_data[i]<<16);
}
}
'디지털회로 > AT91SAM7S256' 카테고리의 다른 글
타이머카운터 (0) | 2011.09.08 |
---|---|
AT91SAM7S256 <-> 하이퍼터미널 통신 (0) | 2011.09.07 |
AT91SAM7S256을 이용한 UART 통신설정 (0) | 2011.09.06 |
1~8번까지 순차적으로 LED 깜빡거리기 (0) | 2011.06.21 |
AT91SAM7S256 실행순서 (0) | 2011.06.21 |