// run: 600kHz: avrdude -pt13 -cusbtiny -Pusb -e -U lfuse:w:0x69:m -U hfuse:w:0xfb:m -U flash:w:C:\arduino\OneWire_ATTINY13_morse_temperature.cpp.hex:i -B 50 // serial debug: 9.6MHz: avrdude -pt13 -cusbtiny -Pusb -e -U lfuse:w:0x7a:m -U hfuse:w:0xfb:m -U flash:w:C:\arduino\OneWire_ATTINY13_morse_temperature.cpp.hex:i -B 50 #define F_CPU 600000 // 600kHz clock //#define F_CPU 9600000 // 9.6MHz clock #define BAUD_RATE 115200 #include #include #include #include //#include #define DS_BIT 4 // pin 3 ATTINY #define RC_BIT1 0 // pin 5 ATTINY #define RC_BIT2 1 // pin 6 ATTINY byte rcbit; struct t_mtab { char c, pat; } ; struct t_mtab morsetab[] = { /* { '-', 97 } , { '.', 106 } , { ',', 115 } , { '?', 76 } , { '/', 41 } , */ { 'A', 6 } , /* { 'B', 17 } , { 'C', 21 } , { 'D', 9 } , { 'E', 2 } , { 'F', 20 } , { 'G', 11 } , { 'H', 16 } , { 'I', 4 } , { 'J', 30 } , */ { 'K', 13 } , /* { 'L', 18 } , { 'M', 7 } , { 'N', 5 } , */ { 'O', 15 } , /* { 'P', 22 } , { 'Q', 27 } , { 'R', 10 } , { 'S', 8 } , { 'T', 3 } , { 'U', 12 } , { 'V', 24 } , { 'W', 14 } , { 'X', 25 } , { 'Y', 29 } , */ { 'Z', 19 } , { '1', 62 } , { '2', 60 } , { '3', 56 } , { '4', 48 } , { '5', 32 } , { '6', 33 } , { '7', 35 } , { '8', 39 } , { '9', 47 } , { '0', 63 } } ; #define N_MORSE (sizeof(morsetab)/sizeof(morsetab[0])) #define SPEED (7) #define DOTLEN (1200/SPEED) #define DASHLEN (3*(1200/SPEED)) // Serial debug //void serOut(const char* str) //{ // while (*str) TxByte (*str++); //} void pause() { // digitalWrite(LEDpin, LOW) ; PORTB &= ~(1 << rcbit); /* LED on */ _delay_ms(DOTLEN); } void dash() { // digitalWrite(LEDpin, HIGH) ; PORTB |= (1 << rcbit); /* LED off */ _delay_ms(DASHLEN); pause(); } void dit() { //digitalWrite(LEDpin, HIGH) ; PORTB |= (1 << rcbit); /* LED off */ _delay_ms(DOTLEN); pause(); } void send(char c) { int8_t i ; if (c == ' ') { //delay(7*DOTLEN) ; _delay_ms(7*DOTLEN); return ; } for (i=0; i>1; } } uint8_t OneWireInByte() { uint8_t d, n,b; for (n=0; n<8; n++) { PORTB &= ~_BV(DS_BIT); DDRB |= _BV(DS_BIT); _delay_us(5); DDRB &= ~_BV(DS_BIT); _delay_us(5); b = ((PINB & _BV(DS_BIT)) != 0); _delay_us(50); d = (d >> 1) | (b<<7); } return(d); } int main() { uint8_t delay_counter=0; byte n = 0; DDRB |= _BV(DS_BIT); PORTB &= ~_BV(DS_BIT); DDRB &= ~_BV(DS_BIT); char Teplota[8], Teplota2[8]; while( 1 ){ /* main event loop */ uint8_t SignBit; uint8_t DSdata[2]; OneWireReset(); OneWireOutByte(0xcc); OneWireOutByte(0x44); DDRB |= (1 << RC_BIT1); DDRB |= (1 << RC_BIT2); PORTB |= _BV(DS_BIT); DDRB |= _BV(DS_BIT); _delay_ms(1000); DDRB &= ~_BV(DS_BIT); PORTB &= ~_BV(DS_BIT); OneWireReset(); OneWireOutByte(0xcc); OneWireOutByte(0xbe); DSdata[0] = OneWireInByte(); DSdata[1] = OneWireInByte(); int8_t TReading = (int)(DSdata[1] << 8) + DSdata[0]; SignBit = TReading & 0x8000; if (SignBit) TReading = (TReading ^ 0xffff) + 1; TReading = (((6 * TReading) + TReading / 4)); // 2345 = 23.45deg of Celsius if (TReading > 0) { rcbit = RC_BIT1; } else { rcbit = RC_BIT2; } // int > 0 TReading = abs(TReading); // round-up of 2 decimal digits TReading = TReading + 50; // convert to chars itoa(TReading,Teplota,10); // serial debug //serOut(Teplota); //serOut(" = "); byte delka = strlen(Teplota); if (delka <= 8) { strncpy(Teplota2, Teplota,delka - 2); Teplota2[delka - 2] = '\0'; }; if (delka <= 2) { Teplota2[0] = '0'; Teplota2[1] = '\0'; }; // serial debug //serOut(Teplota2); //serOut("\n"); // send call sign after 240 temp's cycles n = n + 1; if (n >= 205) { n = 0; sendmsg("OK5AZ"); _delay_ms(2000); } // send temperature sendmsg(Teplota2); TReading = 0; //_delay_ms(1000); // Sleep mode - wait for 8s // temporarily prescale timer to 8s so we can measure current WDTCR |= (1<