int main(){ LCD_Init(); char* dutyString = "Duty: "; char* rpmString = "RPM: "; ////////////// //duty ////////////////////////////////////////////// DDRB = 0xFF; //ouput hbridge PWMSCLA = 0x0C; // 0x0C = 12 PWMCLK = 0x33; PWMPOL = 0x01; PWMCTL = 0x00; PWMPER1 = 100; // 120 //PWMDTY1 = dutyValue; PWME = 0x01; PORTB = 0x08; ////////////////////// //read ////////////////////////////////////////// DDRT &= 0x00; // Enable the Timer System TSCR1 = 0x80; // Make IC channel TIOS = 0x00; //rising edge only TCTL4 = 0x40;//01 //Enable IC3 interrupts TIE = 0x08;//01 UserTimerCh3 = (unsigned short)&IC3_ISR; asm("cli"); // Spin forever while (1){ //dutyValue = dutyCycle(); //PWMDTY1 = dutyValue; _uitoa(dutyValue,&dutyString[6],10); _uitoa(rpmValue,&rpmString[5],10); LCDWriteLine(0x1,dutyString); LCDWriteLine(0x2,rpmString); //delay(100); } return 0; }
static void play_level(void) { start_level(); while (map.done != map.blocks) key(); moveto(0, 0); strcpy(str, "Level "); strcpy(str + 6, _uitoa(level)); strcat(str + 6, " done in "); strcat(str + 6, _uitoa(moves)); strcat(str + 6, " moves."); write(1, str, strlen(str)); getkey(); }
int main(int argc, char *argv[]) { const char *p = _uitoa((int)sysconf(_SC_PAGESIZE)); write(1, p, strlen(p)); write(1, "\n", 1); return 0; }
int new_listen_socket (const char *bindAddr, int nport, int backlog, struct sockaddr_in *addrS) { int soc_ec; int error; char portstring[21]; struct addrinfo hints = {0,}; struct addrinfo *res = NULL; struct addrinfo *rp = NULL; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = 0; hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_PASSIVE | AI_NUMERICSERV; error = getaddrinfo(bindAddr, _uitoa(nport, &portstring), &hints, &res); if (0 != error) { ERROR(L_NOTICE, "server: resolution error in getaddrinfo: %s\n", gai_strerror(error)); return -1; } for (rp = res; rp != NULL; rp = rp->ai_next) { soc_ec = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (soc_ec == -1) continue; if (bind(soc_ec, rp->ai_addr, rp->ai_addrlen) == 0) { memcpy(addrS, rp->ai_addr, sizeof(*addrS)); break; } CLOSE_SOCKET(soc_ec); } freeaddrinfo(res); res = NULL; if (rp == NULL) { ERROR(L_NOTICE, "server: could not bind any address."); return -1; } /* Recovery of the port as network endian */ if (bor_getsockname_in (soc_ec, addrS) < 0) { perror ("getsockname ip"); CLOSE_SOCKET(soc_ec); return -1; } TRACE(L_DEBUG, "server: port %d open", ntohs(addrS->sin_port)); /* Ouverture du service ; le second param est le nb max de connexions pendantes, limite a SOMAXCONN (=128 sur Linux) */ if (listen (soc_ec, backlog) < 0) { perror ("listen"); return -1; } TRACE(L_NOTICE, "server: listening on %s", bor_adrtoa_in (addrS)); return soc_ec; }
void _itoa(int value, char* string, unsigned char radix) { if (value < 0 && radix == 10) { *string++ = '-'; value = -value; } _uitoa(value, string, radix); }
char * SDL_uitoa(unsigned int value, char *string, int radix) { #ifdef HAVE__UITOA return _uitoa(value, string, radix); #else return SDL_ultoa((unsigned long)value, string, radix); #endif /* HAVE__UITOA */ }
int print(int statement,int value){ //subfunction for uitoa if(statement == 1){ char* scoreString = "Score: "; _uitoa(value,&scoreString[7],10); LCDWriteLine(0x1,scoreString); } else if(statement == 2){ //DEBUG char* debugString = "Debug: "; _uitoa(value,&debugString[7],10); LCDWriteLine(0x1,debugString); } else{ char* ahhhString = "ahhhhhh"; LCDWriteLine(0x1,ahhhString); } return; }
/*---------------------------------------------------------------------------*/ void ubasic_error(const char *err) { const char *p; write(2, "\n", 1); if (line_num) { p = _uitoa(line_num); write(2, p, strlen(p)); write(2, ": ", 2); } write(2, err, strlen(err)); write(2, " error.\n", 8); exit(1); }
int main1(void) { word LED = 0; asm("sei"); // disable the global interrupts #ifdef GCC_TOOLCHAIN UserRTI = (unsigned short)&RealTimeInterrupt; // 3e70 UserTimerCh3 = (unsigned short)&Timer3Interrupt; UserTimerCh4 = (unsigned short)&Timer4Interrupt; UserTimerCh5 = (unsigned short)&Timer5Interrupt; // 3e64 UserTimerCh6 = (unsigned short)&Timer6Interrupt; // 3e62 #endif // Port set ups. DDRH = 0x0; // set porth pins to input DIP Switches dipswitch = PTH; // Read the DIP Switches. // LEDs row of LEDs and 7 segs share Port B // PJ1 select the row of LEDs // PTP[0:4] control the 7 segs. Set Lo to select. DDRB = 0xff; // Port B output to LEDS DDRJ |= 0x02; // PJ1 enables the row of LEDS, so make it output. DDRP |= 0xf; // PP0-PP3 Are digit enables for the 7 segs. Set to output. PERP |= 0xf; // Enable pull ups on PP0-PP3. PTP |= 0xf; // Turn off all the digits for now. PTJ &= ~0x2; // Set PJ1 to 0 to turn on LEDS. // At this point what ever you write to PORTB will // show up on the single row of LEDs // After we start running, then stuff will be muxed instead. PORTB = dipswitch; LCD_Init(); LCDWriteLine(1,"Ready..."); PUCR = PUCR | 1; // enable pullups on porta for Key Pad. // ATD block set up. ATD0CTL2 = 0x80; // Enable power up mode for ADC Block ATD0CTL3 = 0x40; // Set 8 bit conversions. // Set the enable digital input for the switches SW1-SW4 ATD0DIEN = 0xff; // LEDOut(LED); rtiCnt = 0; // roll over counter for forground loop. // Set the Real Time Clock Rate RTICTL = 0x10; // 1/(16Mz/2^10) = 64 us or 15.6 ticks per ms // 244us or 4 ticks/ms CRGINT |= 0x80; // enable the interrupt for RTI InitSPI0DAC(); // Set up timer 5 for the speaker. t5delay = 1000; t6delay = 3000; // 1ms t6acc = t6start; TSCR1 = 0x90; // Enable TCNT and fast clear TSCR2 = 0x03; // Set prescaler to 1:8 TIOS |= TIOS_IOS6_MASK; // Enable OC6 for song timer TIOS |= TIOS_IOS4_MASK; // Enable Timer 4 for muxing TIOS |= TIOS_IOS3_MASK; // Enable Timer 3 for DAC waveforms // TIOS |= TIOS_IOS5_MASK; // Disable the speaker until song starts. TCTL1 = 5; // Set toggle mode for OC5 and OC4 TC5 = TCNT + t5delay; // Init the comnpare registers TC6 = TCNT; // This also resets the inturrupt. TIE |= TIOS_IOS5_MASK ; // Enable the timer interrupt bits. TIE |= TIOS_IOS6_MASK; TIE |= TIOS_IOS4_MASK; TIE |= TIOS_IOS3_MASK; // LEDOut(2); // New code // TDBG12printf("\nTEST for miniDragon12+ Hello World!\n"); // Init the EEProm and Flash Burn clocks // #ifdef miniDragon FCLKDIV = ((16000/200/8)-1)+0x40; // Flash CLK = 200 kHz ECLKDIV = ((16000/200/8)-1)+0x40; // Eeprom CLK = 200 kHz #else FCLKDIV = ((4000/200)-1); // Flash CLK = 200 kHz ECLKDIV = ((4000/200)-1); // Eeprom CLK = 200 kHz #endif asm("cli"); // enable the global interrupts // TDBG12printf("\nTEST for Dragon12 Hello World!\n"); LCDWriteLine(1,"Ready..."); LCDSetCharDelay(2, 0x2000); LCDScrollLine(2,initMessage); LCDWriteLine(3,"ABCDEFGHIJKLMNOPQRST"); LCDWriteLine(4,"!@#$%^&*(){}[]:;?><"); for (;;) { // Main forground loop. // Do things at different intervals. LEDSvalue = PTH; // Read the dip switches LCDUpdateScroll(); if (rtiCnt >= LEDCountRate) { ++LED; seg7value = LED; // set the value in the 7 segs. LEDCountRate = LED_COUNT_RATE; if(ReadSwitch( SW5) ) LEDCountRate >>= 1; if(ReadSwitch( SW2) ) LEDCountRate >>= 1; if(ReadSwitch( SW3) ) LEDCountRate >>= 1; if(ReadSwitch( SW4) ) LEDCountRate >>= 1; rtiCnt = 0; } if(0 == rtiCnt % 10 ) { LEDDutyCycle = ReadADC(POT_CHANNEL_NUM); _uitoa(LEDDutyCycle,&LCDMessage[9],10); LCDWriteLine(1,&LCDMessage[0]); if( LEDDutyCycle > 80 ) { LCDSetCharDelay(2, LEDDutyCycle * 50); } } if( 0 == rtiCnt % 2 ) { ScanKeyPad(); } }