int main() { char tegn; char TestStreng[40] = "This string is stored in SRAM memory\r\n"; // Initialize USART // Important : Also other Baud Rates and Data Bits should be tested // Corresponding changes has to be made in the terminal program used // for the test InitUART(9600, 8); while (1) { // Testing SendChar SendChar('A'); SendChar('B'); SendChar('C'); SendChar('\r'); SendChar('\n'); // Testing ReadChar() : Read and echo tegn = ReadChar(); SendChar(tegn); SendChar('\r'); SendChar('\n'); // Testing CharReady() while ( !CharReady() ) {} SendChar( ReadChar() ); SendChar('\r'); SendChar('\n'); // Sending string stored in Flash (constant string) SendString("This string is stored as a constant in flash memory\r\n"); // Sending string stored in SRAM (modify-able string) SendString(TestStreng); // Testing SendInteger() SendInteger(12345); SendChar('\r'); SendChar('\n'); SendInteger(-1000); SendChar('\r'); SendChar('\n'); } }
void runCommand() { int i; SendString("S:"); for (i=0; i<4; i++) SendInteger(cmdbit[i]); SendChar(endByte); }
int main(void) { InitUART(9600, 8); SendString("Hej UART \r\n"); BMP180_Init(102600); while(1) { SendString("Device id: "); SendInteger((int)BMP180_GetDeviceId()); SendString("\r\n \r\n"); SendString("Temperature: "); SendInteger(BMP180_GetTemperature()); SendString("\r\n-----------------\r\n"); _delay_ms(1000); } return 1; }
void main() { int adc_result; InitUART(9600, 8); // UART'en initieres. ///// PWM //////////////// DDRD.5 = 1; // Port D.5(OCR1A) initieres til en udgang. TCCR1A = 0b10000011; // non-inverting TCCR1B = 0b00000010; // Prescale sættes til 8. CS12, CS11 og CS10 sættes til hhv. 010 // Register TCCR1A og B initieres. "Phase Correct PWM mode", 10 bit // OCR1A = 0; // PWM signalet sætter som udgangspunkt til nul. Dioden lyser ved maksimal styrke. ////////////////////////// ////// ADC /////////////// ADMUX = 0b01000000; // Multiplex'eren vælger ADC0, ADLAR = 0, intern 5 volts referance. ADCSRA = 0b11000101; // ADCSRA registeret tændes, div factor på 32(frekvensen ligger mellem 50 og 200 Hz) // Konverteringen sættes igang. ////////////////////////// while(1) { // if(ReadChar() == 'R') { ADCSRA.6 = 1; // Konverteringen startes igen ////// ADC ///////////////// while (ADCSRA.6) // Den springer først over "while", når konverteringen er færdig. {} adc_result = ADCW; // Resultatet fra ADC gemmes i en variabel. SendInteger(adc_result); // Resultatet fra AD konverteringen sendes i terminalen. SendChar('\n'); } } }