Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <tm4c123gh6pm.h>
- #define FIRST_INTERRUPT_NUMBER 16
- char mama_macieja = 0;
- char readChar(void)
- {
- char c;
- while((UART0_FR_R & (1<<4)) != 0);
- c = UART0_DR_R;
- return c;
- }
- char getChar() {
- if (mama_macieja) {
- char x = mama_macieja;
- mama_macieja = 0;
- return x;
- }
- return 0;
- }
- void printChar(char c)
- {
- while((UART0_FR_R & (1<<5)) != 0);
- UART0_DR_R = c;
- }
- void printString(char * string)
- {
- while(*string)
- {
- printChar(*(string++));
- }
- }
- typedef enum EColor {
- GREEN = 0,
- BLUE,
- RED,
- NONE
- };
- static void init(){
- SYSCTL_RCGCUART_R |= (1<<0);
- SYSCTL_RCGCGPIO_R |= (1<<0);
- GPIO_PORTA_AFSEL_R = (1<<1) | (1<<0);
- GPIO_PORTA_PCTL_R = (1<<0) | (1<<4);
- GPIO_PORTA_DEN_R = (1<<0) | (1<<1);
- UART0_CTL_R &= ~(1<<0);
- UART0_IBRD_R = 104;
- UART0_FBRD_R = 11;
- UART0_LCRH_R = (0x3<<5);
- UART0_CTL_R = (1<<0) | (1<<8) | (1<<9);
- SYSCTL_RCGCGPIO_R |= (1<<5);
- SYSCTL_RCGCGPIO_R = 0x20;
- GPIO_PORTF_LOCK_R = 0x4C4F434B;
- GPIO_PORTF_CR_R = 0xff;
- GPIO_PORTF_DIR_R = 0xe;
- GPIO_PORTF_PUR_R = 0x11;
- GPIO_PORTF_DEN_R = 0x1f;
- GPIO_PORTF_IS_R = 0x0;
- GPIO_PORTF_IBE_R = 0x0;
- GPIO_PORTF_IEV_R = 0x0;
- GPIO_PORTF_IM_R = 0x11;
- NVIC_EN0_R |= (1<<(INT_GPIOF-FIRST_INTERRUPT_NUMBER));
- // konfiguracja timer
- SYSCTL_RCGCTIMER_R |= (1<<0); // wylacz timer
- TIMER0_CTL_R &= ~(1<<0);
- TIMER0_CFG_R = 0x0;
- TIMER0_TAMR_R |= (0x2<<0); // okresowy
- TIMER0_TAMR_R &= ~(1<<4); // down
- TIMER0_TAILR_R = 0x00F42400; // 16 mln, bo 16 mhz -- sekunda
- TIMER0_IMR_R |= (1<<0); //w³¹czamy timer
- NVIC_EN0_R |= (1<<(INT_TIMER0A-FIRST_INTERRUPT_NUMBER));
- TIMER0_CTL_R |= (1<<0); // start
- }
- static int timer_w = 1;
- static int F = -1;
- static char blink = 0;
- static enum EColor top[12] = {GREEN, GREEN, GREEN, GREEN, GREEN, BLUE, RED, RED, RED, RED, RED, BLUE};
- static int topIdx = 0;
- static enum EColor bot[2] = {BLUE, RED};
- static int botIdx = 0;
- static void setColor(enum EColor color){
- unsigned char portData;
- switch (color){
- case GREEN:
- portData = (1<<3);
- break;
- case BLUE:
- portData = (1<<2);
- break;
- case RED:
- portData = (1<<1);
- break;
- case NONE:
- portData = ~((1<<1) | (1<<2) | (1<<3));
- break;
- }
- GPIO_PORTF_DATA_R &= 0xF1;
- GPIO_PORTF_DATA_R |= portData;
- }
- void T_Handler(void)
- {
- char c = getChar();
- if (F==0)
- setColor(GREEN);
- if (F==0 && c == 's') {
- F = 2;
- }
- else if (F==1) {
- setColor(top[topIdx++]);
- if (topIdx == 12) {
- F = 0;
- topIdx = 0;
- }
- } else if (F==2) {
- setColor(bot[botIdx++]);
- botIdx %= 2;
- }
- TIMER0_ICR_R |= (1<<0); //przerrwanie obs³u¿one
- }
- void GPIOF_Handler(void)
- {
- char prev_second = 0;
- char first = 0, second = 0;
- switch(GPIO_PORTF_DATA_R & 0x11)
- {
- case 0x00: // dwa
- first = second = 1;
- break;
- case 0x01: // jedna
- first = 1;
- break;
- case 0x10: // druga
- second = 1;
- break;
- }
- if (F==0 && first) {
- F = 1;
- } else if (F==0 && second) {
- } else if (F==2&& second) {
- F = 0;
- botIdx = 0;
- setColor(GREEN);
- }
- GPIO_PORTF_ICR_R = 0x11; // przerwanie obsluzone
- }
- int main()
- {
- init();
- setColor(GREEN);
- F= 0;
- while (1){
- mama_macieja = getChar();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement