This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem, Led Swing on EB40A

Hello!
I've a little problem with my program...
I'm working on the board EB40A (AT91R40008).
This is a code of my simple program:/

#include <stdio.h>
#include <91R40008.H>/* AT91R40008 Definitions */
#include <tc.h>
#include <pio.h>

#ifdef ERAM        /* Store in Flash, Run in RAM */
#define _atr __ram
#else
#define _atr
#endif
void fala(void)
{
     unsigned int i;
     //1
	 for(i=0x00000010;i<<0x00008000;i>>=1)
	 {
	   PIO_SODR = i;
	 while((TC2_SR&0x00000001) == 0x00000000){};
	   PIO_CODR = i;
	 }
	 //4
	 for(i=0x00000040;i>0x00000004;i>>=1)
	 {
	   PIO_SODR = i;
	 while((TC2_SR&0x00000001) == 0x00000000){};
	   PIO_CODR = i;
	 }
}

int main (void) {                          /* Main Program */



  TC2_CMR = TC_CLKS_MCK32;
  TC2_CCR = TC_CLKEN;
  PIO_PER  = 0x000F0078;
  PIO_OER  = 0x000F0078;
  while((PIO_PDSR&0x00000002) == 0x00000000){};
  while((PIO_PDSR&0x00000002) == 0x00000002){};
  TC2_CCR = TC_SWTRG;
     PIO_SODR = 0x00000008;
	 while((TC2_SR&0x00000001) == 0x00000000){};
	 PIO_CODR = 0x00000008;
	while(1)
	{
	 TC2_CMR = TC_CLKS_MCK32;
	 while((PIO_PDSR&0x00000004) == 0x00000000){fala();}
	 while((PIO_PDSR&0x00000004) == 0x00000004){fala();}
	 TC2_CMR = TC_CLKS_MCK8;
	 while((PIO_PDSR&0x00000004) == 0x00000000){fala();}
	 while((PIO_PDSR&0x00000004) == 0x00000004){fala();}
	 TC2_CMR = TC_CLKS_MCK2;
	 while((PIO_PDSR&0x00000004) == 0x00000000){fala();}
	 while((PIO_PDSR&0x00000004) == 0x00000004){fala();}

	 }
	 }
This program is simple Led Swing. This swing starts when i push and release a button(PIO_PDSR&0x00000002)and then (with timer2 support) my leds swing with definite by MCK speed.

This speed must change in this way: first push and release button(PIO_PDSR&0x00000004) sets the clock on MCK32, second push and release button sets clock on MCK8, third - MCK2...It works but only if leds "meet" pushed button at their start point and then "meet" released button at the start point of their swing and then the speed changes...

Could You help me to run this program right? after any of leds off program must check the push and release button...I dont know how to do that...:(

0