Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "..//tm4c123gh6pm.h"
- #include "PWM1.h"
- // ***************** Timer0_Init ****************
- // Activate TIMER0 interrupts to run user task periodically
- // Inputs: task is a pointer to a user function
- // period in units (1/clockfreq)
- // Outputs: none
- #define RED_LED 0x2
- #define BLUE_LED 0x4
- #define GREEN_LED 0x8
- #define TAPWMIE (1 << 9)
- #define TAAMS (1 << 3)
- #define TACMR 0x02
- #define TAMR (1 << 1)
- #define TAWPML (1 << 6)
- #define TAPLO (1 << 11)
- #define TAWOT (1 << 6)
- #define TAMIE (1 << 5)
- //Interrupts defines
- //GPTM Timer A Match Interrupt Mask
- #define TATOIM (1 << 0) //GPTM Timer A Time-Out Interrupt Mask
- #define TAMIM (1 << 4)
- extern void DisableInterrupts(void); // Disable interrupts
- extern void EnableInterrupts(void); // Enable interrupts
- extern void WaitForInterrupt(void); // low power mode
- static const unsigned long LED[] = {RED_LED , BLUE_LED, GREEN_LED, 0x0};
- void configureInterruptPWM()
- {
- NVIC_PRI5_R = (NVIC_PRI5_R&0xFFFFFF00) | 0x00000000; // 8) priority 4
- NVIC_EN0_R = (1<<19); // 9) enable IRQ 19 in NVIC
- }
- volatile unsigned long ledNR = 0;
- void nextLED(void)
- {
- ledNR++;
- }
- void previousLED(void)
- {
- ledNR--;
- }
- void PWM1_Init(unsigned long longSignal){
- configureInterruptPWM();
- SYSCTL_RCGCTIMER_R |= 0x01; // 0) activate TIMER0
- TIMER0_CTL_R &= ~0x00000001; // 1) disable TIMER0A during setup
- TIMER0_CFG_R = 0x00; // 2) configure for 32-bit mode
- TIMER0_TAMR_R = 0x02 | TAMIE; // 3) configure for periodic mode, default down-count settings;
- TIMER0_TAPR_R = 0x0;
- TIMER0_TAPMR_R = 0x0001;
- TIMER0_TAILR_R = 0x0ffff;
- TIMER0_TAMATCHR_R = 0xf;
- TIMER0_ICR_R = TIMER_ICR_TAMCINT | TIMER_ICR_TATOCINT; // 6) clear TIMER0A timeout flag
- TIMER0_IMR_R = TATOIM | TAMIM;
- TIMER0_CTL_R |= 0x00000001; // 10) enable TIMER0A
- }
- void Timer0A_Handler(void)
- {
- //Timeout
- unsigned long myLed = ledNR & 3;
- if (TIMER0_RIS_R & 0x1)
- {
- NVIC_EN0_R = (1<<30);
- TIMER0_ICR_R = TIMER_ICR_TATOCINT;// acknowledge TIMER1A timeout
- DisableInterrupts();
- GPIO_PORTF_DATA_R |= LED[myLed];
- EnableInterrupts();
- //GPIO_PORTF_DATA_R |= LED[0];
- //GPIO_PORTF_DATA_R |= LED[1];
- } //Match
- else if (TIMER0_RIS_R & (1 << 4))
- {
- TIMER0_ICR_R = TIMER_ICR_TAMCINT;
- DisableInterrupts();
- GPIO_PORTF_DATA_R &= ~(LED[myLed]);
- EnableInterrupts();
- //GPIO_PORTF_DATA_R &= ~(LED[0]);
- //GPIO_PORTF_DATA_R &= ~(LED[1]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement