void main (void) { char ch; // Used to store character from UART unsigned char c; // Used to store character from UART FLADDR bla; PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer // enable) PORT_Init(); // Initialize Port I/O SYSCLK_Init (); // Initialize Oscillator UART0_Init(); P3_0 = 1; P3_2 = 1; EA = 0; bla = 0x0000; while (1) { ch = FLASH_ByteRead(bla); c = FLASH_ByteRead(bla); printf ("\n0x%x: 0x%x %d", bla , c, c+1); bla ++; if (bla == 0x3e00) break; } P3_0 = 1; P3_2 = 0; while (1); }
void main (void) { float period; PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer enable) PORT_Init(); // Initialize Port I/O SYSCLK_Init (); // Initialize Oscillator UART0_Init(); // Initialize UART0 TIMER0_Init(); printf("\x1b[2J"); // Clear screen using ANSI escape sequence. printf ("Period measurement at pin P0.1 using Timer 0.\n" "File: %s\n" "Compiled: %s, %s\n\n", __FILE__, __DATE__, __TIME__); while (1) { // Reset the counter TL0=0; TH0=0; TF0=0; overflow_count=0; while(P0_1!=0); // Wait for the signal to be zero while(P0_1!=1); // Wait for the signal to be one TR0=1; // Start the timer while(P0_1!=0) // Wait for the signal to be zero { if(TF0==1) // Did the 16-bit timer overflow? { TF0=0; overflow_count++; } } while(P0_1!=1) // Wait for the signal to be one { if(TF0==1) // Did the 16-bit timer overflow? { TF0=0; overflow_count++; } } TR0=0; // Stop timer 0, the 24-bit number [overflow_count-TH0-TL0] has the period! period=(overflow_count*65536.0+TH0*256.0+TL0)*(12.0/SYSCLK); // Send the period to the serial port printf( "\rf=%fs" , period); heart_rate = 1.0/(period/60.0); bpm = (int) heart_rate; LCDprint(bpm, 1, 5); //print heart rate bpm to LCD display } }
/* init the emif using the lower port */ void EMIF_Low(void) { SYSCLK_Init(); EMI0CF = 0x1F; // non-multiplexed mode, external only XBR2 = 0x42; // Enable xbr P0MDOUT = 0xC0; P1MDOUT = 0xFF; P2MDOUT = 0xFF; P3MDOUT = 0xFF; }
void BSP_Init(void) { SYSCLK_Init(); SysTick_Init(); LED_Config(); Out_GPIO_Init(); In_GPIO_Init(); UART1_Init(UART1_BAUD); UART2_Init(UART2_BAUD); }
void main (void) { char keypress; WDTCN = 0xde; // disable watchdog timer WDTCN = 0xad; SYSCLK_Init (); // initialize oscillator UART0_Init (); // initialize UART0 XBR0 = 0x04; // Route UART to GPIO XBR1 = 0x14; XBR2 = 0xC0; // Enable crossbar P1MDOUT = 0x03; //1.0 and 1.1 are push pull to set interrupts //IP = 0x04; //set int1 priority to high zero = 0x01; //pin is initially high one = 0x01; //init IE = 0x85; //enable interrupts printf ("\nEE587 Experiment #5\n"); printf ("Initialization Complete...\n"); printf ("Press h for help...\n"); while (1) { printf("What would you like to do? (l,s,h):"); keypress = 'l'; //getchar(); printf("\n"); switch(keypress) { case ' ':; case 's': //short interrupt = first interrupt with longInt = 0 zero = 0x00; break; case 'l': //long interrupt = interrupt -> trigger second interrupt -> return to a divide -> second interrupt longInt =1; //set the flag to cause a long interrupt zero = 0x00; //trigger first interrupt x=5.0/x; //a division for the zero interrupt to return to before the one interrupt is called break; case 'h': //help printf ("Press l to cause a long latency interrupt\n"); printf ("Press s to cause a short latency interrupt\n"); break; default: printf("Invalid Command '%c'\n",keypress); break; } } // while(1) } // main
void main() { WDTCN=0XDE; WDTCN=0XAD; SYSCLK_Init(); PORT_Init(); UART0_Init(); while(1) { SBUF0 = 'A'; while(!TI0); TI0=0; } }
void main() { unsigned int i; WDTCN=0xDE; WDTCN=0xAD; SYSCLK_Init(); PORT_Init(); SPI0_Init(); Mp3Reset(); P7 &= ~0x40; for (i = 0; i < 15000; ++i) send_dat(music[i]); flush_buffer(); while(1); }
int main() { //time init structure struct tm ti; struct tm ret; //RTC_SetTime(14,20,00); ti.tm_hour = 14; ti.tm_min = 20; ti.tm_sec = 00; //RTC_SetDate(8,11,2013); ti.tm_mday = 8; ti.tm_mon = 11; ti.tm_year = 2013; //RTC_SetDays(5 ,365); ti.tm_wday = 5; ti.tm_yday = 365; SYSCLK_Init(1000); /* Acertar o clock do TIMER*/ RTC_Init(&ti); LCD_Init(); char buffer [16]; while(1) { RTC_GetValue(&ret); LCD_Goto(0,0); strftime(buffer,16,"%T",&ret); LCD_WriteString(buffer); } return 0; }
void main (void) { SFRPAGE = ACTIVE_PAGE; // Change for PCA0MD PCA0MD &= ~0x40; // Disable watchdog timer PORT_Init (); // Initialize Port I/O SYSCLK_Init (); // Initialize Oscillator UART0_Init (); // Initialize UART EA = 1; // Enable global interrutpts while (1) { // If the complete word has been entered via the terminal followed by // carriage return if((TX_Ready == 1) && (UART_Buffer_Size != 0) && (Byte == 13)) { TX_Ready = 0; // Set the flag to zero TI0 = 1; // Set transmit flag to 1 } } }
void main(void){ WDTCN = 0xde; // disable watchdog timer WDTCN = 0xad; SYSCLK_Init (); // initialize oscillator UART0_Init (); // initialize UART0 P74OUT = 0x08; //port 5 high bit is push pull XBR0 = 0x04; // Route only uart0 XBR1 = 0x00; XBR2 = 0xC0; // Enable crossbar without weak pullups P5 = 0x0FF; //start P5 PCA0CN = 0x40; PCA0MD = 0x09; printf("Enter a clock divider value between 1 and 65535: "); scanf("%u",&number); //get the number from the user if(number > 0){ //number may not be 0.. cant divide by 0 divider = number; //set the clock divider used in the blinking counter = 0; //reset the counter printf("\n"); printf("I received %u", divider); } else{ printf("\nNumber may NOT be 0\n"); } EIE1 = 0x08; //enable CF interrupts IE = 0x80; //enable interrupts globally, UART0 while(1); //spin forever } //main
void main (void) { char keypress; WDTCN = 0xde; // disable watchdog timer WDTCN = 0xad; SYSCLK_Init (); // initialize oscillator //PORT_Init (); // initialize crossbar and GPIO UART0_Init (); // initialize UART0 //OSCICN |= 0x03; // Set internal oscillator to highest setting // (16 MHz) XBR0 = 0x05; // Route SMBus to GPIO pins through crossbar XBR2 = 0x44; // Enable crossbar and weak pull-ups P1MDOUT = 0x03; SMB0CN = 0x44; // Enable SMBus with ACKs on acknowledge // cycle SMB0CR = -80; // SMBus clock rate = 100kHz. EIE1 |= 2; // SMBus interrupt enable EA = 1; // Global interrupt enable SM_BUSY = 0; // Free SMBus for first transfer. //SMBus_Init(); //Timer3_Init(); //Interrupts_Init(); //SI = 0; printf ("EE587 Experiment #3\n"); printf ("Initialization Complete...\n"); while (1) { printf("what would you like to do? (d,b,r,w):"); keypress = getchar(); printf("\n"); switch(keypress) { case 'd': dump_eeprom(); break; case 'b': block_fill(); break; case 'r': read_eeprom(); break; case 'w': write_eeprom(); break; case ' ':; default: printf("Invalid Command '%c'\n",keypress); break; } } // while(1) } // main
void main (void) { int reflection,LDs_count,omron_count,angel; int old_fix,fix,left,right; unsigned char reflect,status,k; char old_flag,flag; WDTCN = 0xDE; // disable watchdog timer WDTCN = 0xAD; SYSCLK_Init (); // Initialize system clock to 16MHz ExtCrystalOsc_Init (); // switch system clock Port_Init (); // Initialize crossbar and GPIO SPI0_Init(); LED_Init(); // Initialize OLED Sensors_Init(); Rudder_Init(); Motor_Init(); Measurement_Init(); Test_Helper_Init(); EA = 1; // Enable global interrupts CR = 1; // start to output PWM P31 = 1; PUT_LINE("OMRON:",omron_count); PUT_LINE("reflection:",reflection); PUT_LINE("LDs_count:",LDs_count); PUT_LINE("Tunnel1:",tunnel_length[0]); PUT_LINE("Tunnel2:",0); PUT_LINE("Tunnel3:",0); //PUT_LINE("angel:",angel); //PUT_LINE("fix:",fix); while (1) { // Spin forever DIRECTION = 0; PCA0CPH1 = 0xE0; flag = 0; while (1) { // dectecting reflect = get_LD_reflection(); old_flag = flag; flag = 0; // conner emergency if(reflect < 25){ if(!LEFT3 && RIGHT3) flag = 1; if(!RIGHT3 && LEFT3) flag = -1; if(flag) break; } // go straight forward: if(!LEFT1 || !LEFT2 || !LEFT3) flag = 1; if(!RIGHT1 && LEFT2) flag = -1; if(!RIGHT2 && LEFT3) flag = -1; if(!RIGHT3) flag = -1; k = 7; if(reflect > 50){ k = 10; } if(reflect > 85){ if(flag > 0) if(++left > 32766) { left = left - right; right = 0; } if(flag < 0) if(++right > 32766) { right = right - left; left = 0; } old_fix = fix; fix = left - right; if(fix > 20) fix = 20; if(fix < -20) fix = -20; fix = ((fix + RUDDER_FIX) + old_fix)/2; } //UPDATE_VALUE(5,fix); if(MAX_REFLECTION > reflect) angel = MAX_REFLECTION - reflect; else angel = 0; angel = flag * k * angel / 10 + fix; //UPDATE_VALUE(4,angel); set_angel(angel); // debug info omron_count = Get_OMRON_Count(); reflection = get_LD_reflection(); LDs_count = TL1 + LD2_count; UPDATE_VALUE(0,omron_count); UPDATE_VALUE(1,reflection); UPDATE_VALUE(2,LDs_count/3); tmp = tunnel_length[1] * 464 / 1683; UPDATE_VALUE(3,tmp); tmp = tunnel_length[2] * 464 / 1683; UPDATE_VALUE(4,tmp); tmp = tunnel_length[3] * 464 / 1683; UPDATE_VALUE(5,tmp); } reflect = get_LD_reflection(); if(reflect < 10){ // 60 degree PCA0CPH1 = 0xB8; set_angel(flag * 127); Clear_OMRON_Count(); while(omron_count <= 300); while(1){ if(flag > 0 && !LEFT1) { while(!RIGHT1); break; } if(flag < 0 && !RIGHT1) { while(!LEFT1); break; } } }else{ // 90 degree DIRECTION = 1; PCA0CPH1 = 0x38; Clear_OMRON_Count(); set_angel(-flag * 127); while(1){ omron_count = Get_OMRON_Count(); UPDATE_VALUE(0,omron_count); if(omron_count >= 410) //1062 break; } DIRECTION = 0; PCA0CPH1 = 0xB8; //Clear_OMRON_Count(); set_angel(flag * 127); // escape from conner while(1){ if(flag > 0 && !LEFT1){ while(!RIGHT1); break; } if(flag < 0 && !RIGHT1){ while(!LEFT1); break; } // if } // while } // if else: 60 or 90 degree } // main loop } // main
int main() { unsigned int nextState; unsigned int actualStateButton = 0; //Define a a data e hora que o sistema vai ter inicialmente //RTC_SetTime(00,00,00); ti.tm_hour = 00; ti.tm_min = 00; ti.tm_sec = 00; //RTC_SetDate(8,11,2013); ti.tm_mday = 8; ti.tm_mon = 11; ti.tm_year = 2013; //RTC_SetDays(5 ,365); ti.tm_wday = 5; ti.tm_yday = 365; //System init SYSCLK_Init(1000); /* Acertar o clock do TIMER*/ RTC_Init(&ti); /* Iniciar o RTC com a data e hora definida inifialmente*/ LCD_Init(); LCD_Clear(); I2C_Init(); RADIO_Init(); RADIO_SetFreq(89.9); WriteData(); while(1) { actualStateButton = Button_Read(); nextState = decodeButtons(actualStateButton); switch(nextState) { case CHANGE_HOURS: changeHours(&ti); break; case CHANGE_RADIO: changeRadio(&tea); LCD_Clear(); break; //Tambem devia de escrever a freq do radio case SHOW: RTC_GetValue(&ti); LCD_Goto(4,0); strftime(buffer,16,"%T",&ti); LCD_WriteString(buffer); ReadData(&tea); float fm = RADIO_GetFreq(&tea); int level = RADIO_Station_Level(&tea); int parteDecimal = (int)(fm*10)%10; sprintf(buffer, "%d.%dMHz L:%d",(int)fm,parteDecimal, level); LCD_Goto(0,1); LCD_WriteString(buffer); break; default: break; } } return 0; }