0x00,0x00,0x20,0x90,0x00,0x00,0x02,0x12,0x00,0x21,0x20,0x00,0x00,0x02,0x10,0x80, 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0x00,0x02,0x22,0x00,0x00,0x44,0x40,0x00, 0x08,0x21,0x05,0xF6,0x61,0x00,0x1F,0x1F,0x06,0x1F,0x1F,0x1F,0x1F,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x90, 0x00,0x00,0x02,0x22,0x00,0x21,0x10,0x10,0x00,0x04,0x11,0x00,0x00,0x00,0x00,0x00, 0x80,0x00,0x10,0x02,0x00,0x01,0x11,0x00,0x04,0x48,0x80,0x00,0x08,0x19,0x06,0x38, }; /// List of button pins that must be configured for use by the application. static const Pin pPins[] = {PINS_DBGU}; static const Pin pinPB1 = PIN_PUSHBUTTON_1; static const Pin pinPB2 = PIN_PUSHBUTTON_2;
static const Pin pLCDDataPins[]={ LCDD0,LCDD1,LCDD2,LCDD3,LCDD4,LCDD5,LCDD6,LCDD7}; static const Pin pinLCDCS=LCDCS; static const Pin pinLCDWR = LCDWR; static const Pin pinLCDA0=LCDA0;
/// Indicates the current state (on or off) for each LED. static unsigned char pLedStates[2] = {1, 1};
/// Global timestamp in milliseconds since start of application. volatile unsigned int timestamp = 0;
//------------------------------------------------------------------------------ // Local functions //------------------------------------------------------------------------------
//------------------------------------------------------------------------------ /// Handler for PIT interrupt. Increments the timestamp counter. //------------------------------------------------------------------------------ static void ISR_Pit(void) { unsigned int status;
// Read the PIT status register status = PIT_GetStatus() & AT91C_PITC_PITS; if (status != 0) {
// Read the PIVR to acknowledge interrupt and get number of ticks timestamp += (PIT_GetPIVR() >> 20); } }
//------------------------------------------------------------------------------ /// Configure the periodic interval timer to generate an interrupt every /// millisecond. //------------------------------------------------------------------------------ static void ConfigurePit(void) { // Initialize the PIT to the desired frequency PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000);
// Configure interrupt on PIT AIC_DisableIT(AT91C_ID_SYS); AIC_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit); AIC_EnableIT(AT91C_ID_SYS); PIT_EnableIT();
// Enable the pit PIT_Enable(); }
//------------------------------------------------------------------------------ /// Interrupt handler for pushbutton #1. Starts or stops LED#1. //------------------------------------------------------------------------------ static void ISR_Bp1(void) { static unsigned int lastPress = 0;
// Check if the button has been pressed if (!PIO_Get(&pinPB1)) {
// Simple debounce method: limit push frequency to 1/DEBOUNCE_TIME // (i.e. at least DEBOUNCE_TIME ms between each push) if ((timestamp - lastPress) > DEBOUNCE_TIME) {
lastPress = timestamp;
// Toggle LED state pLedStates[0] = !pLedStates[0]; if (!pLedStates[0]) {
LED_Clear(0); } } } }
//------------------------------------------------------------------------------ /// Interrupt handler for pushbutton #2. Starts or stops LED#2 and TC0. //------------------------------------------------------------------------------ static void ISR_Bp2(void) { static unsigned int lastPress = 0;
// Check if the button has been pressed if (!PIO_Get(&pinPB2)) {
// Simple debounce method: limit push frequency to 1/DEBOUNCE_TIME // (i.e. at least DEBOUNCE_TIME ms between each push) if ((timestamp - lastPress) > DEBOUNCE_TIME) {
lastPress = timestamp;
// Disable LED#2 and TC0 if there were enabled if (pLedStates[1]) {
pLedStates[1] = 0; LED_Clear(1); AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; } // Enable LED#2 and TC0 if there were disabled else {
pLedStates[1] = 1; LED_Set(1); AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; } } } }
//------------------------------------------------------------------------------ /// Configure the pushbuttons to generate interrupts. //------------------------------------------------------------------------------ static void ConfigureButtons(void) { #if defined(at91sam7lek) || defined(at91cap9dk) const Pin pinCol0 = PIN_KEYBOARD_COL0; PIO_Configure(&pinCol0, 1); #endif
// Configure pios PIO_Configure(&pinPB1, 1); PIO_Configure(&pinPB2, 1);
// Initialize interrupts PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST); PIO_ConfigureIt(&pinPB1, (void (*)(const Pin *)) ISR_Bp1); PIO_ConfigureIt(&pinPB2, (void (*)(const Pin *)) ISR_Bp2); PIO_EnableIt(&pinPB1); PIO_EnableIt(&pinPB2); }
//------------------------------------------------------------------------------ /// Configure LEDs #1 and #2 (cleared by default). //------------------------------------------------------------------------------ static void ConfigureLeds(void) { LED_Configure(0); LED_Configure(1); }
//------------------------------------------------------------------------------ /// Interrupt handler for TC0 interrupt. Toggles the state of LED #2 //------------------------------------------------------------------------------ static void ISR_Tc0(void) { // Clear status bit to acknowledge interrupt AT91C_BASE_TC0->TC_SR;
// Toggle LED state LED_Toggle(1); printf("2 "); }
//------------------------------------------------------------------------------ /// Configure Timer Counter 0 to generate an interrupt every 250ms. //------------------------------------------------------------------------------ static void ConfigureTc(void) { unsigned int div; unsigned int tcclks;
// Enable peripheral clock AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC0;
// Configure TC for a 4Hz frequency and trigger on RC compare TC_FindMckDivisor(4, BOARD_MCK, &div, &tcclks); TC_Configure(AT91C_BASE_TC0, tcclks | AT91C_TC_CPCTRG); AT91C_BASE_TC0->TC_RC = (BOARD_MCK / div) / 4; // timerFreq / desiredFreq
// Configure and enable interrupt on RC compare AIC_ConfigureIT(AT91C_ID_TC0, AT91C_AIC_PRIOR_LOWEST, ISR_Tc0); AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; AIC_EnableIT(AT91C_ID_TC0);
// Start the counter if LED is enabled. if (pLedStates[1]) {
TC_Start(AT91C_BASE_TC0); } }
//------------------------------------------------------------------------------ /// Waits for the given number of milliseconds (using the timestamp generated /// by the PIT). /// param delay Delay to wait for, in milliseconds. //------------------------------------------------------------------------------ static void Wait(unsigned long delay) { volatile unsigned int start = timestamp; unsigned int elapsed; do { elapsed = timestamp; elapsed -= start; } while (elapsed < delay); }
//------------------------------------------------------------------------------ // Exported functions //------------------------------------------------------------------------------
/// Write Data to LCD Controller /// Sequence: LCDWR low --> LCDCS low --> Write Data // -->LCDWR hign -->LCDCS high // if CMD is 1,then as a Command void WritetoLCD(unsigned char ucData,unsigned char CMD) { unsigned int i,j;
PIO_Clear(&pinLCDCS); PIO_Clear(&pinLCDWR); //for(j=0;j<10;j++); //delay if (CMD == 0) //is date PIO_Clear(&pinLCDA0); else //cmd==1 is address set command PIO_Set(&pinLCDA0);
//for(j=0;j<10;j++); //delay for ( i = 0 ; i < 8; i++) { if (((ucData>>i) & 0x1)==1) PIO_Set(&pLCDDataPins); else PIO_Clear( &pLCDDataPins); } //for(j=0;j<10;j++); //delay
//for(j=0;j<2;j++); //delay PIO_Set(&pinLCDWR); //for(j=0;j<1;j++); //delay PIO_Set(&pinLCDCS); //for(j=0;j<1;j++); //delay }
//------------------------------------------------------------------------------ /// Main function //------------------------------------------------------------------------------ int main() { int i,j,k; PIO_Configure(pPins, PIO_LISTSIZE(pPins)); PIO_Configure(pLCDDataPins, PIO_LISTSIZE(pLCDDataPins)); PIO_Configure(&pinLCDCS, 1); PIO_Configure(&pinLCDWR, 1); PIO_Configure(&pinLCDA0, 1);
DBGU_Configure(DBGU_STANDARD, 115200, BOARD_MCK); printf("-- Getting Started Project 1.4 --
"); printf("Board : %s, Chip ID : 0x%08X
", BOARD_NAME, AT91C_BASE_DBGU->DBGU_CIDR);
// Configuration ConfigurePit(); ConfigureTc(); //ConfigureButtons(); //ConfigureLeds();
//for(k=0;k<10000;k++;) for (j=0;j<5;j++) Wait(500); while (1) { for(k=0;k<5;k++) { WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) {WritetoLCD( (((i*j*k)%65535)&0xff),0); WritetoLCD(((((i*j*k)%65535)>>8)&0xff),0); } for (j=0;j<15;j++) Wait(500); WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) {if (i<272/3) {WritetoLCD(0xfc,0),WritetoLCD(i&0xff,0);} else if (i<272/3*2) {WritetoLCD(0x03,0),WritetoLCD(j&0xff,0);} else if (i<272/3*3) {WritetoLCD(j&0xff,0),WritetoLCD(j&0xff,0) ;} } } WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480/8;j++) {for(k=0;k<8;k++) if (((pic[480/8*i+j]>>(7-k)) & 0x1)==1) {WritetoLCD(0xff,0);WritetoLCD(0xff,0);} else {WritetoLCD(0x00,0);WritetoLCD(0x00,0);}} for (j=0;j<15;j++) Wait(500); /* WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) // {WritetoLCD((char)j,0); } {if (j==240) WritetoLCD(0xff,0);else WritetoLCD(0x00,0);} for (j=0;j<15;j++) Wait(500); */ WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) { if (j==0 || i==0 || j==240 ||j==210 ||j==211 || i==j || i==j+5 ) { WritetoLCD(0xf0|j,0);WritetoLCD(0x0f|j,0);} else { WritetoLCD(0x00,0);WritetoLCD(0x00,0);} } for (j=0;j<5;j++) Wait(500); /* WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) { if(i==j) WritetoLCD(0xff,0); else WritetoLCD(0x00,0); } */ WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 //for (j=0;j<5;j++) Wait(500); //for(i=0;i<272;i++) // for (j=0;j<480;j++) // {WritetoLCD(0x00,0); } //for (j=0;j<5;j++) Wait(500); WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 //for(i=0;i<272;i++) for (j=0;j<480;j++) { WritetoLCD(j,0);WritetoLCD(j,0); } for (j=0;j<5;j++) Wait(500); // } // ................................................................... WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) { //if (((i>20) && (i<240) && (j>20) && (j<460) && (j%10==0))|| (i%10==0)) if((i%40==0)||(j%40==0)) {WritetoLCD(0xff,0); WritetoLCD(i&0xff,0); } //write date else {WritetoLCD(0x00,0);WritetoLCD(0x00,0); } /* if ((i==130) && (j==470)) if (i&0x1==1) {WritetoLCD(0x00,0); } //write date else {WritetoLCD(0xff,0);} */ // Wait(500); } for (j=0;j<15;j++) Wait(500); WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) { //if ((i>20) && (i<240) && (j>20) && (j<460)) if((i%10==0)||(j%10==2)) {WritetoLCD(0x00,0);WritetoLCD(0x00,0); } //write date else {WritetoLCD(i,0);WritetoLCD(i,0);} /* if ((i==130) && (j==470)) if (i&0x1==1) {WritetoLCD(0x00,0); } //write date else {WritetoLCD(0xff,0);} */ // Wait(500); } for (j=0;j<15;j++) Wait(500); for(k=1;k<240;k=2*k+1) { WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0;i<272;i++) for (j=0;j<480;j++) { // {if (((j==0)||(j==479))) WritetoLCD(0xff,0);else WritetoLCD(0x00,0);} //if ((i>k) && (i<272-k) && (j>k) && (j<480-k) ) if(((i%k)==0)||((j%k)==0)) { if (k%1) {WritetoLCD(0xff,0);WritetoLCD(i&0xff,0);} else {WritetoLCD(0x00,0);WritetoLCD(0x00,0);} } //write date else {if (!(k%1)) {WritetoLCD(0xff,0);WritetoLCD(j&0xff,0);} else {WritetoLCD(0x00,0);WritetoLCD(0x00,0);}} } // for (j=0;j<15;j++) Wait(500); Wait(500); WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0,1);//reset display ram pointer to 0 for(i=0,j=0;i<15;i++) { for (j=0;j<k*8;j++) { if (j%8<4) {WritetoLCD(0x00,0);WritetoLCD(0x00,0);} else {WritetoLCD(0x0f,0);WritetoLCD(0xf0,0);} } for(;j<480;j++) {WritetoLCD(0xff,0);WritetoLCD(0x1,0);} } for(i=0;i<5;i++) for (j=0;j<480;j++) {WritetoLCD(0x00,0);WritetoLCD(0x00,0);} for(i=0;i<5;i++) for (j=0;j<480;j++) {WritetoLCD(i&0xff,0);WritetoLCD(j&0xff,0);} for(i=0,j=0;i<15;i++) { for (j=0;j<k*8;j++) { if (j%8<4) {WritetoLCD(j&0xff,0);WritetoLCD(i&0xff,0);} else {WritetoLCD(0x00,0);WritetoLCD(0x00,0); } } for(;j<480;j++) {WritetoLCD(0x00,0);WritetoLCD(0x00,0);} }
for (j=0;j<15;j++) Wait(500); } } //........................................................................... for (j=0;j<5;j++) Wait(500); WritetoLCD(0,1);//reset display ram pointer to 0 WritetoLCD(0x00,0); //write date WritetoLCD(0xff,0);WritetoLCD(0xff,0); //write date for (j=0;j<5;j++) Wait(500); WritetoLCD(0,1);//reset display ram pointer to 0
/* for (j=0;j<5;j++) Wait(500); for ( i = 0 ; i < 9600;i++ ) { WritetoLCD(0xFE,0); } for (j=0;j<5;j++) Wait(500); for (j=0;j<5;j++) Wait(500); for ( i = 0 ; i < 9600;i++ ) { WritetoLCD(0x7F,0); } for (j=0;j<5;j++) Wait(500); for ( i = 0 ; i < 9600;i++ ) { WritetoLCD(0xFF,0); } */ for (j=0;j<5;j++) Wait(500); for ( i = 0 ; i < 9600;i++ ) { WritetoLCD((char)(0xff),0); WritetoLCD((char)(0xff),0); } for (j=0;j<5;j++) Wait(500); for ( i = 0 ; i < 9600;i++ ) { WritetoLCD((char)(i&0xff),0); WritetoLCD((char)(i&0xff),0); } for (j=0;j<5;j++) Wait(500); for ( i = 9600*2 ; i < 480*270*2;i++ ) { WritetoLCD((char)(0),0); WritetoLCD((char)(0),0); } WritetoLCD(0,0); //write date WritetoLCD(0,0); //write date for (j=0;j<5;j++) Wait(500); for(;;); { for ( i = 0 ; i < 9600;i++ ) { WritetoLCD((char)(k&0xff),0); //write date } for (j=0;j<10;j++) Wait(500); } WritetoLCD(0,0); //write date WritetoLCD(0,0); //write date Wait(500); WritetoLCD(0x81,0); //write date WritetoLCD(0x81,0); //write date Wait(500);
} |