پاسخ : مشکل با IAR
ممنون از پاسخ شما ..
مشکلم رو بیان کردم کدهارو هم اضافه میکنم... :redface:
main.c :
handleLCD.h :
نوشته اصلی توسط aliila
مشکلم رو بیان کردم کدهارو هم اضافه میکنم... :redface:
main.c :
کد:
#include "ioat91sam7s64.h" //#include "delay.h" int delay(unsigned int ms); #include "handleLCD.h" void main() { AT91C_BASE_CKGR->CKGR_MOR = (0x8<<8)|(0x1<<0); while(!(AT91C_BASE_PMC->PMC_SR & (0x1))); // AT91C_BASE_WDTC->WDTC_WDMR = 0x3FFF3258; // while(!(AT91C_BASE_WDTC->WDTC_WDMR & (0x3FFF312C))); AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS; AT91C_BASE_AIC->AIC_IDCR = 0xffffffff; AT91C_BASE_PMC->PMC_MCKR = 0x1; while(!(AT91C_BASE_PMC->PMC_SR & (0x8))); AT91C_BASE_PMC->PMC_SCER = 0x1; while(!(AT91C_BASE_PMC->PMC_SCSR & (0x1))); AT91C_BASE_PMC->PMC_PCER = (1<<2); while(!(AT91C_BASE_PMC->PMC_PCSR & (0x4))); handleLCD(); lcdInit(); // lcdInit(); lcdClear(); /////////////////////////////// /////////////////////////////// lcdGoToXY(2,1); while(1){ // AT91C_BASE_WDTC->WDTC_WDCR = (0xA5000001); lcdWriteText("Ashkan"); } } int delay(unsigned int ms){ unsigned long int i,j; while(ms) { for (i=0;i<100;i++) for(j=0;j<25;j++); ms--; } return 0; }
کد:
/* edited by ashkan anousheh */ #include "string.h" #ifndef handleLCD_h #define handleLCD_h #define _E 1 #define _Rs 2 #define _Rw 7 #define _D4 3 #define _D5 4 #define _D6 5 #define _D7 6 int handleLCD(); int lcdGoToXY(char x, char y); int lcdGoToAddr(char addr); int lcdInit(); int lcdClear(); int lcdWriteText(char *text); int clr_screen(); int shift_screen(int s,int x); int sendCommand(char opCode); int sendCommand4Bit(char opCode); #endif int handleLCD() { AT91C_BASE_PMC->PMC_PCER = (1<<2); AT91C_BASE_PIOA->PIO_PER = (1<<_E)|(1<<_Rs)|(1<<_Rw)|(1<<_D4)|(1<<_D5)|(1<<_D6)|(1<<_D7); AT91C_BASE_PIOA->PIO_OER = (1<<_E)|(1<<_Rs)|(1<<_Rw)|(1<<_D4)|(1<<_D5)|(1<<_D6)|(1<<_D7); AT91C_BASE_PIOA->PIO_PPUDR = (1<<_E)|(1<<_Rs)|(1<<_Rw)|(1<<_D4)|(1<<_D5)|(1<<_D6)|(1<<_D7); AT91C_BASE_PIOA->PIO_OWER = (1<<_E)|(1<<_Rs)|(1<<_Rw)|(1<<_D4)|(1<<_D5)|(1<<_D6)|(1<<_D7); return 0; } int lcdGoToXY(char x, char y) { char addr=0; switch(x) { case 0: addr = 0x00; break; //Starting address of 1st line case 1: addr = 0x40; break; //Starting address of 2nd line case 2: addr = 0x14; break; //Starting address of 3rd line case 3: addr = 0x54; break; //Starting address of 4th line default: ; } addr +=y; lcdGoToAddr(addr); return 0; } int lcdGoToAddr(char addr) { char cmd = 0x80 | addr; AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rs); AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rw); sendCommand4Bit(cmd); return 0; } int lcdInit() { //Set all the control pins to logic Zero AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rs); AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rw); AT91C_BASE_PIOA->PIO_ODSR = (0<<_E); return 0; //Do the wake up call delay(40); sendCommand(0x30); delay(40); sendCommand(0x30); delay(40); sendCommand(0x30); delay(40); sendCommand(0x20); //Let's make it 4 bit mode delay(40); //That's it LCD is initialized in 4 bit mode. sendCommand4Bit(0x28); //N = 1 (2 line display) F = 0 (5x8 characters) sendCommand4Bit(0x08); //Display on/off control D=0,C=0, B=0 sendCommand4Bit(0x01); //Clear Display sendCommand4Bit(0x06); //Entry mode set - I/D = 1 (increment cursor) & S = 0 (no shift) sendCommand4Bit(0x0C); //Display on/off control. D = 1, C and B = 0. (Cursor and blink, last two bits) } int lcdClear() { AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rs); sendCommand4Bit(0x01); return 0; } int lcdWriteText(char *text) { //char strTxt[] = *text; //int x = strlen(strTxt); for(;*text<strlen(text);) { AT91C_BASE_PIOA->PIO_ODSR = (1<<_Rs); sendCommand4Bit(*text++); } return 0; } int lcdBusy() { AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rs); AT91C_BASE_PIOA->PIO_ODR = (1<<_D7); AT91C_BASE_PIOA->PIO_ODSR = (1<<_Rw); int busyFlag = 1; while(busyFlag == 1) { //The data should be read while Enable pin is HIGH AT91C_BASE_PIOA->PIO_ODSR = (1<<_E); busyFlag = (AT91C_BASE_PIOA->PIO_PDSR & (0x40)); AT91C_BASE_PIOA->PIO_ODSR = (0<<_E); //Clock out the lower part of data, since we are interested in only the //upper part. more precissaley D7 pin. AT91C_BASE_PIOA->PIO_ODSR = (1<<_E); AT91C_BASE_PIOA->PIO_ODSR = (0<<_E); } AT91C_BASE_PIOA->PIO_OER = (1<<_D7); AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rw); return 0; } int sendCommand(char opCode) { AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x10)<<_D4); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x20)<<_D5); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x40)<<_D6); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x80)<<_D7); // lcdBusy(); delay(20); return 0; } int sendCommand4Bit(char opCode) { AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x10)<<_D4); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x20)<<_D5); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x40)<<_D6); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x80)<<_D7); AT91C_BASE_PIOA->PIO_ODSR = (1<<_E); delay(1); AT91C_BASE_PIOA->PIO_ODSR = (0<<_E); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x01)<<_D4); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x02)<<_D5); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x04)<<_D6); AT91C_BASE_PIOA->PIO_ODSR = ((opCode & 0x08)<<_D7); AT91C_BASE_PIOA->PIO_ODSR = (1<<_E); delay(1); AT91C_BASE_PIOA->PIO_ODSR = (0<<_E); delay(20); return 0; } int clr_screen() { lcdBusy(); AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rs); AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rw); sendCommand4Bit(0x01); return 0; } int shift_screen(int s,int x) { lcdBusy(); AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rs); AT91C_BASE_PIOA->PIO_ODSR = (0<<_Rw); if (s==0) { for(;x>0;x--) { sendCommand4Bit(0x18); } } if(s==1) { for(;x>0;x--) { sendCommand4Bit(0x1c); } } return 0; }
دیدگاه