Тема: ATtiny2313 + DHT11 (Arduino IDE)
Помогите подружить Тиньку с датчиком DHT21
Вы не вошли. Пожалуйста, войдите или зарегистрируйтесь.
forum.rcl-radio.ru → Переделки → ATtiny2313 + DHT11 (Arduino IDE)
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
Помогите подружить Тиньку с датчиком DHT21
Опрос DHT21 аналогичен DHT11, только DHT11 не содержит некоторых данных.
Массив data_dht[] имеет 5 значений data_dht[0] влажность целое data_dht[1] влажность после запятой ,
data_dht[2] температура целое data_dht[3] температура после запятой.
Может поможете Sketch изменить у меня Sketch с сайта показывает t 55, H 53.
Хотя с этим датчиком ардуинка показывает нормальные данные t 23, H 20.
Должно получится что то типа этого:
byte data_dht[5];
void setup(){}
void loop() {
dht_read();
delay(3000);
print_time(data_dht[2]*10|data_dht[3],2,7,1);
delay(3000);
print_time(data_dht[0]*10|data_dht[1],2,7,0);
}
void tm_dec(byte dig){
for(int i = 0; i < 8; i++) {
DDRB |= (1 << 0);del();
if (dig & 0x01)
DDRB &= ~(1 << 1);
else
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
dig = dig >> 1;
}
DDRB |= (1 << 0);
DDRB &= ~(1 << 1);del();
DDRB &= ~(1 << 0);del();
if (((PINB >> 1) & 1) == 0)
DDRB |= (1 << 1);del();
DDRB |= (1 << 0);del();
}
void tm_stop(){
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
DDRB &= ~(1 << 1);del();
}
void tm_start(){
DDRB |= (1 << 1);del();
}
void print_time(int t, byte pd_t, int br, bool mn){
tm_start();tm_dec(0b10001000 + br);//tm_stop();tm_start();
tm_dec(0x40);tm_stop();tm_start();
int data0;
if(mn == 1){data0 = 11;}else{data0 = 12;}
int data1 = 10;
int data2 = t / 10 % 10;
int data3 = t % 10;
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
case 11: data = 0b01111000;break; // t
case 12: data = 0b01110110;break; // H
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
switch(pd_t){
case 1 : data2 = data2+0b10000000;break;
case 2 : data1 = data1+0b10000000;break;
case 3 : data0 = data0+0b10000000;break;
}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delayMicroseconds(200);}
int dht_read(){
byte i = 0,i1 = 0;
for(i = 0;i < 5;i++){data_dht[i] = 0;}
DDRB |=(1 << 2);
PORTB &= ~(1 << 2);
delay(1);
PORTB |= (1 << 2);
delayMicroseconds(60);
DDRB &= ~(1 << 2);
delayMicroseconds(80);
while(PINB & (1 << 2));
for (i = 0; i < 5; i++){
data_dht[i]=0;
for (i1=0; i1<8; i1++){
while(!(PINB & (1 << 2)));
delayMicroseconds(30);
if (PINB & (1 << 2)){data_dht[i] |= 1 << (7-i1);}
while(PINB & (1 << 2));
}}return 1;}
Попробуйте этот код:
byte data_dht[5];
void setup(){}
void loop() {
dht_read();
delay(3000);
print_time(data_dht[2]*10|data_dht[3],0,0,0);
delay(3000);
print_time(data_dht[0]*10|data_dht[1],0,0,0);
}
void tm_dec(byte dig){
for(int i = 0; i < 8; i++) {
DDRB |= (1 << 0);del();
if (dig & 0x01)
DDRB &= ~(1 << 1);
else
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
dig = dig >> 1;
}
DDRB |= (1 << 0);
DDRB &= ~(1 << 1);del();
DDRB &= ~(1 << 0);del();
if (((PINB >> 1) & 1) == 0)
DDRB |= (1 << 1);del();
DDRB |= (1 << 0);del();
}
void tm_stop(){
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
DDRB &= ~(1 << 1);del();
}
void tm_start(){
DDRB |= (1 << 1);del();
}
void print_time(int t, byte pd_t, int br, bool mn){
tm_start();tm_dec(0b10001000 + br);//tm_stop();tm_start();
tm_dec(0x40);tm_stop();tm_start();
int data0;
if(mn == 1){data0 = 11;}else{data0 = 12;}
int data1 = 10;
int data2 = t / 10 % 10;
int data3 = t % 10;
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
case 11: data = 0b01111000;break; // t
case 12: data = 0b01110110;break; // H
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
switch(pd_t){
case 1 : data2 = data2+0b10000000;break;
case 2 : data1 = data1+0b10000000;break;
case 3 : data0 = data0+0b10000000;break;
}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delayMicroseconds(200);}
int dht_read(){
byte i = 0,i1 = 0;
for(i = 0;i < 5;i++){data_dht[i] = 0;}
DDRB |=(1 << 2);
PORTB &= ~(1 << 2);
delay(1);
PORTB |= (1 << 2);
delayMicroseconds(60);
DDRB &= ~(1 << 2);
delayMicroseconds(80);
while(PINB & (1 << 2));
for (i = 0; i < 5; i++){
data_dht[i]=0;
for (i1=0; i1<8; i1++){
while(!(PINB & (1 << 2)));
delayMicroseconds(30);
if (PINB & (1 << 2)){data_dht[i] |= 1 << (7-i1);}
while(PINB & (1 << 2));
}}return 1;}
Может это поможет
float DHT::readTemperature(bool S, bool force) {
float f = NAN;
if (read(force)) {
switch (_type) {
case DHT11:
f = data[2];
if (data[3] & 0x80) {
f = -1 - f;
}
f += (data[3] & 0x0f) * 0.1;
if (S) {
f = convertCtoF(f);
}
break;
case DHT12:
f = data[2];
f += (data[3] & 0x0f) * 0.1;
if (data[2] & 0x80) {
f *= -1;
}
if (S) {
f = convertCtoF(f);
}
break;
case DHT22:
case DHT21:
f = ((word)(data[2] & 0x7F)) << 8 | data[3];
f *= 0.1;
if (data[2] & 0x80) {
f *= -1;
}
if (S) {
f = convertCtoF(f);
}
break;
}
}
return f;
Последняя попытка:
byte data_dht[5];
void setup(){}
void loop() {
dht_read();
delay(3000);
print_time(data_dht[2]*10|data_dht[3],0,7,1);
delay(3000);
print_time(data_dht[0]*10|data_dht[1],0,7,0);
}
void tm_dec(byte dig){
for(int i = 0; i < 8; i++) {
DDRB |= (1 << 0);del();
if (dig & 0x01)
DDRB &= ~(1 << 1);
else
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
dig = dig >> 1;
}
DDRB |= (1 << 0);
DDRB &= ~(1 << 1);del();
DDRB &= ~(1 << 0);del();
if (((PINB >> 1) & 1) == 0)
DDRB |= (1 << 1);del();
DDRB |= (1 << 0);del();
}
void tm_stop(){
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
DDRB &= ~(1 << 1);del();
}
void tm_start(){
DDRB |= (1 << 1);del();
}
void print_time(int t, byte pd_t, int br, bool mn){
tm_start();tm_dec(0b10001000 + br);//tm_stop();tm_start();
tm_dec(0x40);tm_stop();tm_start();
int data0;
if(mn == 1){data0 = 11;}else{data0 = 12;}
int data1 = t /100;
int data2 = t / 10 % 10;
int data3 = t % 10;
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
case 11: data = 0b01111000;break; // t
case 12: data = 0b01110110;break; // H
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
switch(pd_t){
case 1 : data2 = data2+0b10000000;break;
case 2 : data1 = data1+0b10000000;break;
case 3 : data0 = data0+0b10000000;break;
}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delayMicroseconds(200);}
int dht_read(){
byte i = 0,i1 = 0;
for(i = 0;i < 5;i++){data_dht[i] = 0;}
DDRB |=(1 << 2);
PORTB &= ~(1 << 2);
delay(1);
PORTB |= (1 << 2);
delayMicroseconds(60);
DDRB &= ~(1 << 2);
delayMicroseconds(80);
while(PINB & (1 << 2));
for (i = 0; i < 5; i++){
data_dht[i]=0;
for (i1=0; i1<8; i1++){
while(!(PINB & (1 << 2)));
delayMicroseconds(30);
if (PINB & (1 << 2)){data_dht[i] |= 1 << (7-i1);}
while(PINB & (1 << 2));
}}return 1;}
Мне в чужом коде очень трудно разобраться
Загрузите этот код чтобы проверить индикатор
byte data_dht[5];
void setup(){}
void loop() {
// dht_read();
delay(3000);
print_time(255,0,7,1);
delay(3000);
print_time(255,0,7,0);
}
void tm_dec(byte dig){
for(int i = 0; i < 8; i++) {
DDRB |= (1 << 0);del();
if (dig & 0x01)
DDRB &= ~(1 << 1);
else
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
dig = dig >> 1;
}
DDRB |= (1 << 0);
DDRB &= ~(1 << 1);del();
DDRB &= ~(1 << 0);del();
if (((PINB >> 1) & 1) == 0)
DDRB |= (1 << 1);del();
DDRB |= (1 << 0);del();
}
void tm_stop(){
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
DDRB &= ~(1 << 1);del();
}
void tm_start(){
DDRB |= (1 << 1);del();
}
void print_time(int t, byte pd_t, int br, bool mn){
tm_start();tm_dec(0b10001000 + br);//tm_stop();tm_start();
tm_dec(0x40);tm_stop();tm_start();
int data0;
if(mn == 1){data0 = 11;}else{data0 = 12;}
int data1 = t /100;
int data2 = t / 10 % 10;
int data3 = t % 10;
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
case 11: data = 0b01111000;break; // t
case 12: data = 0b01110110;break; // H
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
switch(pd_t){
case 1 : data2 = data2+0b10000000;break;
case 2 : data1 = data1+0b10000000;break;
case 3 : data0 = data0+0b10000000;break;
}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delayMicroseconds(200);}
int dht_read(){
byte i = 0,i1 = 0;
for(i = 0;i < 5;i++){data_dht[i] = 0;}
DDRB |=(1 << 2);
PORTB &= ~(1 << 2);
delay(1);
PORTB |= (1 << 2);
delayMicroseconds(60);
DDRB &= ~(1 << 2);
delayMicroseconds(80);
while(PINB & (1 << 2));
for (i = 0; i < 5; i++){
data_dht[i]=0;
for (i1=0; i1<8; i1++){
while(!(PINB & (1 << 2)));
delayMicroseconds(30);
if (PINB & (1 << 2)){data_dht[i] |= 1 << (7-i1);}
while(PINB & (1 << 2));
}}return 1;}
может проц поменять или изменить ногу проца для датчика,только я не знаю как
Я неправильно собираю байт:
Сейчас попробую собрать как положено
На экране Н меняется на t?
byte data_dht[5];
void setup(){}
void loop() {
dht_read();
delay(3000);
print_time(data_dht[2]*256+data_dht[3],0,7,1);
delay(3000);
print_time(data_dht[0]*256+data_dht[1],0,7,0);
}
void tm_dec(byte dig){
for(int i = 0; i < 8; i++) {
DDRB |= (1 << 0);del();
if (dig & 0x01)
DDRB &= ~(1 << 1);
else
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
dig = dig >> 1;
}
DDRB |= (1 << 0);
DDRB &= ~(1 << 1);del();
DDRB &= ~(1 << 0);del();
if (((PINB >> 1) & 1) == 0)
DDRB |= (1 << 1);del();
DDRB |= (1 << 0);del();
}
void tm_stop(){
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
DDRB &= ~(1 << 1);del();
}
void tm_start(){
DDRB |= (1 << 1);del();
}
void print_time(int t, byte pd_t, int br, bool mn){
tm_start();tm_dec(0b10001000 + br);//tm_stop();tm_start();
tm_dec(0x40);tm_stop();tm_start();
int data0;
if(mn == 1){data0 = 11;}else{data0 = 12;}
int data1 = t /100;
int data2 = t / 10 % 10;
int data3 = t % 10;
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
case 11: data = 0b01111000;break; // t
case 12: data = 0b01110110;break; // H
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
switch(pd_t){
case 1 : data2 = data2+0b10000000;break;
case 2 : data1 = data1+0b10000000;break;
case 3 : data0 = data0+0b10000000;break;
}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delayMicroseconds(200);}
int dht_read(){
byte i = 0,i1 = 0;
for(i = 0;i < 5;i++){data_dht[i] = 0;}
DDRB |=(1 << 2);
PORTB &= ~(1 << 2);
delay(1);
PORTB |= (1 << 2);
delayMicroseconds(100);
DDRB &= ~(1 << 2);
delayMicroseconds(80);
while(PINB & (1 << 2));
for (i = 0; i < 5; i++){
data_dht[i]=0;
for (i1=0; i1<8; i1++){
while(!(PINB & (1 << 2)));
delayMicroseconds(30);
if (PINB & (1 << 2)){data_dht[i] |= 1 << (7-i1);}
while(PINB & (1 << 2));
}}return 1;}
Жаль что у меня нет такого датчика, хотелось разобраться как его запускать.
В даташите есть картинка
По коду:
int dht_read(){
byte i = 0,i1 = 0;
for(i = 0;i < 5;i++){data_dht[i] = 0;}
DDRB |=(1 << 2);
PORTB &= ~(1 << 2); // делаю низкий уровень
delay(1); // жду 1 мс
PORTB |= (1 << 2); // делаю высокий уровень
delayMicroseconds(100); // жду 100 мкс пропуская паузу в 20 мкс и 80 мкс
DDRB &= ~(1 << 2); // делаю пин как вход
delayMicroseconds(80); // жду последние 80 мкс до начала данных
while(PINB & (1 << 2));
for (i = 0; i < 5; i++){
data_dht[i]=0;
for (i1=0; i1<8; i1++){
while(!(PINB & (1 << 2)));
delayMicroseconds(26);
if (PINB & (1 << 2)){data_dht[i] |= 1 << (7-i1);}
while(PINB & (1 << 2));
}}return 1;}
Вроде все верно, единственной замените строку:
delayMicroseconds(30);
на
delayMicroseconds(26);
так как на картинке указано что не более 26 мкс
Если не получится, то все, не имея модуля на руках я не смогу его запустить.
Тоже самое, жаль удобный датчик с корпусом
Спасибо за помощь
byte data_dht[5];
void setup(){
}
void loop() {
dht_read();
delay(3000);
print_time(data_dht[2]*256+data_dht[3],0,7,1);
delay(3000);
print_time(data_dht[0]*256+data_dht[1],0,7,0);
}
void tm_dec(byte dig){
for(int i = 0; i < 8; i++) {
DDRB |= (1 << 0);del();
if (dig & 0x01)
DDRB &= ~(1 << 1);
else
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
dig = dig >> 1;
}
DDRB |= (1 << 0);
DDRB &= ~(1 << 1);del();
DDRB &= ~(1 << 0);del();
if (((PINB >> 1) & 1) == 0)
DDRB |= (1 << 1);del();
DDRB |= (1 << 0);del();
}
void tm_stop(){
DDRB |= (1 << 1);del();
DDRB &= ~(1 << 0);del();
DDRB &= ~(1 << 1);del();
}
void tm_start(){
DDRB |= (1 << 1);del();
}
void print_time(int t, byte pd_t, int br, bool mn){
tm_start();tm_dec(0b10001000 + br);//tm_stop();tm_start();
tm_dec(0x40);tm_stop();tm_start();
int data0;
if(mn == 1){data0 = 11;}else{data0 = 12;}
int data1 = t /100;
int data2 = t / 10 % 10;
int data3 = t % 10;
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
case 11: data = 0b01111000;break; // t
case 12: data = 0b01110110;break; // H
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
switch(pd_t){
case 1 : data2 = data2+0b10000000;break;
case 2 : data1 = data1+0b10000000;break;
case 3 : data0 = data0+0b10000000;break;
}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delayMicroseconds(200);}
int dht_read(){
byte i = 0,i1 = 0;
for(i = 0;i < 5;i++){data_dht[i] = 0;}
DDRB |=(1 << 2);
PORTB &= ~(1 << 2);
delay(1);
PORTB |= (1 << 2);
delayMicroseconds(80);
DDRB &= ~(1 << 2);
delayMicroseconds(60);
while(PINB & (1 << 2));
for (i = 0; i < 5; i++){
data_dht[i]=0;
for (i1=0; i1<8; i1++){
while(!(PINB & (1 << 2)));
delayMicroseconds(26);
if (PINB & (1 << 2)){data_dht[i] |= 1 << (7-i1);}
while(PINB & (1 << 2));
}}return 1;}
t008 h008 не изменилась.
После нового года DHT22 приедет с ним попробую
DHT22_TM1637. Схема подключения стандартная,но внутренний кварц на 8Мгц. В инструментах платы отключить millis()/micros(). На отрицательных температурах не тестировал. Как-то так получилось...
//#define TEMP_MASK 0x7FFF
#define DHT22_PIN 2 // датчик DHT22
byte c=0,temperature_hi, temperature_lo, humidity_hi, humidity_lo, dig1,dig2,dig3, check_sum;
int temperature_result, humidity_result;
#define TM1637_DIO_HIGH() (PORTB |= _BV(TM1637_DIO_PIN))
#define TM1637_DIO_LOW() (PORTB &= ~_BV(TM1637_DIO_PIN))
#define TM1637_DIO_OUTPUT() (DDRB |= _BV(TM1637_DIO_PIN))
#define TM1637_DIO_INPUT() (DDRB &= ~_BV(TM1637_DIO_PIN))
#define TM1637_DIO_READ() (((PINB & _BV(TM1637_DIO_PIN)) > 0) ? 1 : 0)
#define TM1637_CLK_HIGH() (PORTB |= _BV(TM1637_CLK_PIN))
#define TM1637_CLK_LOW() (PORTB &= ~_BV(TM1637_CLK_PIN))
// TM1637 Main Settings
#define TM1637_DIO_PIN PB1 // дисплей TM1637
#define TM1637_CLK_PIN PB0 // дисплей TM1637
#define TM1637_BRIGHTNESS_MAX (7)
#define TM1637_POSITION_MAX (4)
// TM1637 commands
#define TM1637_CMD_SET_DATA 0x40
#define TM1637_CMD_SET_ADDR 0xC0
#define TM1637_CMD_SET_DSIPLAY 0x80
// TM1637 data settings (use bitwise OR to contruct complete command)
#define TM1637_SET_DATA_WRITE 0x00 // write data to the display register
#define TM1637_SET_DATA_READ 0x02 // read the key scan data
#define TM1637_SET_DATA_A_ADDR 0x00 // automatic address increment
#define TM1637_SET_DATA_F_ADDR 0x04 // fixed address
#define TM1637_SET_DATA_M_NORM 0x00 // normal mode
#define TM1637_SET_DATA_M_TEST 0x10 // test mode
// TM1637 display control command set (use bitwise OR to consruct complete command)
#define TM1637_SET_DISPLAY_OFF 0x00 // off
#define TM1637_SET_DISPLAY_ON 0x08 // on
static uint8_t _config = TM1637_SET_DISPLAY_ON | TM1637_BRIGHTNESS_MAX;
static uint8_t _segments = 0xff;
PROGMEM const uint8_t _digit2segments[] =
{
0x3F, // 0
0x06, // 1
0x5B, // 2
0x4F, // 3
0x66, // 4
0x6D, // 5
0x7D, // 6
0x07, // 7
0x7F, // 8
0x6F // 9
};
void setup() {
TM1637_init(1/*включить*/, 7/*яркость*/);
for(byte i=0;i<5;i++){
TM1637_display_segments(i, 64);
}
delay(3000); //Ждём пока датчик настроится.
}
void loop() {
request(); /* стартовый импульс */
response();
humidity_lo=receive_data(); /* целое число влажности */
humidity_hi=receive_data(); /* дробное число влажности */
temperature_lo=receive_data(); /* целое число температуры */
temperature_hi=receive_data(); /* дробное число температуры */
check_sum=receive_data(); /* контрольная сумма */
/*
if ((get_checksum() & 255) != check_sum) { если ошибка датчика
print_error();
}
else {humidity_result = (humidity_lo * 256 + humidity_hi );
temperature_result = (temperature_lo * 256 + temperature_hi ); }
*/
/*
if(temperature_result > TEMP_MASK) { если отрицательная температура
negative_temp = -(TEMP_MASK & temperature_result);
*/
humidity_result = (humidity_lo * 256 + humidity_hi );
temperature_result = (temperature_lo * 256 + temperature_hi );
dig1 = temperature_result / 100;
byte temporary = temperature_result % 100;
dig2 = temporary / 10;
dig3 = temporary % 10;
TM1637_display_digit(0, dig1);
TM1637_display_digit(1, dig2);
TM1637_display_digit(2, dig3);
TM1637_display_segments(3, 99);
delay(3000);
dig1 = humidity_result / 100;
temporary = humidity_result % 100;
dig2 = temporary / 10;
dig3 = temporary % 10;
TM1637_display_digit(0, dig1);
TM1637_display_digit(1, dig2);
TM1637_display_digit(2, dig3);
TM1637_display_segments(3, 118);
delay(3000);
}
/*
* датчик dht22
*/
void request() {
DDRB |= (1<<DHT22_PIN);
PORTB &= ~(1<<DHT22_PIN); /* set to low pin */
delay(20); /* wait for 20ms */
PORTB |= (1<<DHT22_PIN); /* set to high pin */
}
void response() {
DDRB &= ~(1<<DHT22_PIN);
while(PINB & (1<<DHT22_PIN));
while((PINB & (1<<DHT22_PIN))==0);
while(PINB & (1<<DHT22_PIN));
}
uint8_t receive_data() {
int q;
for (q=0; q<8; q++) {
while((PINB & (1<<DHT22_PIN)) == 0); /* check received bit 0 or 1 */
delayMicroseconds(30);
if(PINB & (1<<DHT22_PIN))/* if high pulse is greater than 30ms */
c = (c<<1)|(0x01); /* then its logic HIGH */
else /* otherwise its logic LOW */
c = (c<<1);
while(PINB & (1<<DHT22_PIN));
}
return c;
}
//int get_checksum() {
// return humidity_lo + humidity_hi + temperature_lo + temperature_hi;}
/*
* библиотека дисплея TM1637
*/
void delay1sec(void)
{
// Generated by delay loop calculator
// at http://www.bretmulvey.com/avrdelay.html
//
// Delay 1 000 000 cycles
// 1s at 1 MHz
asm volatile (
" ldi r18, 6" "\n"
" ldi r19, 19" "\n"
" ldi r20, 174" "\n"
"1: dec r20" "\n"
" brne 1b" "\n"
" dec r19" "\n"
" brne 1b" "\n"
" dec r18" "\n"
" brne 1b" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
};
void
TM1637_init(const uint8_t enable, const uint8_t brightness)
{
DDRB |= (_BV(TM1637_DIO_PIN)|_BV(TM1637_CLK_PIN));
PORTB &= ~(_BV(TM1637_DIO_PIN)|_BV(TM1637_CLK_PIN));
TM1637_send_config(enable, brightness);
}
void
TM1637_enable(const uint8_t value)
{
TM1637_send_config(value, _config & TM1637_BRIGHTNESS_MAX);
}
void
TM1637_set_brightness(const uint8_t value)
{
TM1637_send_config(_config & TM1637_SET_DISPLAY_ON,
value & TM1637_BRIGHTNESS_MAX);
}
void
TM1637_display_segments(const uint8_t position, const uint8_t segments)
{
TM1637_send_command(TM1637_CMD_SET_DATA | TM1637_SET_DATA_F_ADDR);
TM1637_start();
TM1637_write_byte(TM1637_CMD_SET_ADDR | (position & (TM1637_POSITION_MAX - 1)));
TM1637_write_byte(segments);
TM1637_stop();
}
void
TM1637_display_digit(const uint8_t position, const uint8_t digit)
{
uint8_t segments = (digit < 10 ? pgm_read_byte_near((uint8_t *)&_digit2segments + digit) : 0x00);
if (position == 0x01) {
segments = segments | (_segments & 0x80);
_segments = segments;
}
TM1637_display_segments(position, segments);
}
void
TM1637_display_colon(const uint8_t value)
{
if (value) {
_segments |= 0x80;
} else {
_segments &= ~0x80;
}
TM1637_display_segments(0x01, _segments);
}
void
TM1637_clear(void)
{
uint8_t i;
for (i = 0; i < TM1637_POSITION_MAX; ++i) {
TM1637_display_segments(i, 0x00);
}
}
void
TM1637_send_config(const uint8_t enable, const uint8_t brightness)
{
_config = (enable ? TM1637_SET_DISPLAY_ON : TM1637_SET_DISPLAY_OFF) |
(brightness > TM1637_BRIGHTNESS_MAX ? TM1637_BRIGHTNESS_MAX : brightness);
TM1637_send_command(TM1637_CMD_SET_DSIPLAY | _config);
}
void
TM1637_send_command(const uint8_t value)
{
TM1637_start();
TM1637_write_byte(value);
TM1637_stop();
}
void
TM1637_start(void)
{
TM1637_DIO_HIGH();
TM1637_CLK_HIGH();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
TM1637_DIO_LOW();
}
void
TM1637_stop(void)
{
TM1637_CLK_LOW();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
TM1637_DIO_LOW();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
TM1637_CLK_HIGH();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
TM1637_DIO_HIGH();
}
uint8_t
TM1637_write_byte(uint8_t value)
{
uint8_t i, ack;
for (i = 0; i < 8; ++i, value >>= 1) {
TM1637_CLK_LOW();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
if (value & 0x01) {
TM1637_DIO_HIGH();
} else {
TM1637_DIO_LOW();
}
TM1637_CLK_HIGH();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
}
TM1637_CLK_LOW();
TM1637_DIO_INPUT();
TM1637_DIO_HIGH();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
ack = TM1637_DIO_READ();
if (ack) {
TM1637_DIO_OUTPUT();
TM1637_DIO_LOW();
}
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
TM1637_CLK_HIGH();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
TM1637_CLK_LOW();
// Delay 5 cycles, 5us at 1 MHz
asm volatile (
" lpm" "\n"
" rjmp 1f" "\n"
"1:" "\n"
);
TM1637_DIO_OUTPUT();
return ack;
}
Тоже самое только по другому
#define DHT22_PIN PB2 // датчик DHT22
byte c=0,temperature_hi, temperature_lo, humidity_hi, humidity_lo, dig1,dig2,dig3, check_sum;
int temperature_result, humidity_result;
#define CLK PB0 // TM1637
#define DIO PB1 // TM1637
void setup() {
//ждём пока датчик настроится.
delay(3000);
}
void loop() {
request(); /* стартовый импульс */
response();
humidity_lo=receive_data(); /* целое число влажности */
humidity_hi=receive_data(); /* дробное число влажности */
temperature_lo=receive_data(); /* целое число температуры */
temperature_hi=receive_data(); /* дробное число температуры */
check_sum=receive_data(); /* контрольная сумма */
/*
if ((get_checksum() & 255) != check_sum) { если ошибка датчика
print_error();
}
else {humidity_result = (humidity_lo * 256 + humidity_hi );
temperature_result = (temperature_lo * 256 + temperature_hi ); }
*/
/*
if (temperature_lo > 127)
{ // если отрицательная температура
temperature_lo = temperature_lo - 128;
}
else {};
*/
humidity_result = (humidity_lo * 256 + humidity_hi );
temperature_result = (temperature_lo * 256 + temperature_hi );
//dig1 = temperature_result / 100;
//byte temporary = temperature_result % 100;
//dig2 = temporary / 10;
//dig3 = temporary % 10;
print_time(humidity_result,2,7,0);
delay(3000);
//dig1 = humidity_result / 100;
//temporary = humidity_result % 100;
//dig2 = temporary / 10;
//dig3 = temporary % 10;
print_time(temperature_result,2,7,1);
delay(3000);
}
/*
* датчик dht22
*/
void request() {
DDRB |= (1<<DHT22_PIN);
PORTB &= ~(1<<DHT22_PIN); /* set to low pin */
delay(20); /* wait for 20ms */
PORTB |= (1<<DHT22_PIN); /* set to high pin */
}
void response() {
DDRB &= ~(1<<DHT22_PIN);
while(PINB & (1<<DHT22_PIN));
while((PINB & (1<<DHT22_PIN))==0);
while(PINB & (1<<DHT22_PIN));
}
uint8_t receive_data() {
int q;
for (q=0; q<8; q++) {
while((PINB & (1<<DHT22_PIN)) == 0); /* check received bit 0 or 1 */
delayMicroseconds(30);
if(PINB & (1<<DHT22_PIN))/* if high pulse is greater than 30ms */
c = (c<<1)|(0x01); /* then its logic HIGH */
else /* otherwise its logic LOW */
c = (c<<1);
while(PINB & (1<<DHT22_PIN));
}
return c;
}
//int get_checksum() {
// return humidity_lo + humidity_hi + temperature_lo + temperature_hi;}
/*
* библиотека дисплея TM1637
*/
void tm_dec(byte dig){
for(byte i = 0; i < 8; i++) {
DDRB |= (1 << CLK);del();
if (dig & 0x01)
DDRB &= ~(1 << DIO);
else
DDRB |= (1 << DIO);del();
DDRB &= ~(1 << CLK);del();
dig = dig >> 1;
}
DDRB |= (1 << CLK);
DDRB &= ~(1 << DIO);del();
DDRB &= ~(1 << CLK);del();
if (((PINB >> DIO) & 1) == 0)
DDRB |= (1 << DIO);del();
DDRB |= (1 << CLK);del();
}
void tm_stop(){
DDRB |= (1 << DIO);del();
DDRB &= ~(1 << CLK);del();
DDRB &= ~(1 << DIO);del();
}
void tm_start(){
DDRB |= (1 << DIO);del();
}
void print_time(int t, byte pd_t, int br, bool mn){
tm_start();tm_dec(0b10001000 + br);//tm_stop();tm_start();
tm_dec(0x40);tm_stop();tm_start();
int data0 = t/ 100;
int data1 = (t % 100)/10;
int data2 = (t % 100) % 10;
int data3;
if(mn == 1){data3 = 11;}else{data3 = 12;}
for(byte n = 0; n < 4; n++){
int data;
switch(n){
case 0: data = data0;break;
case 1: data = data1;break;
case 2: data = data2;break;
case 3: data = data3;break;
}
switch(data){ // XGFEDCBA
case 0: data = 0b00111111;break; // 0
case 1: data = 0b00000110;break; // 1
case 2: data = 0b01011011;break; // 2
case 3: data = 0b01001111;break; // 3
case 4: data = 0b01100110;break; // 4
case 5: data = 0b01101101;break; // 5
case 6: data = 0b01111101;break; // 6
case 7: data = 0b00000111;break; // 7
case 8: data = 0b01111111;break; // 8
case 9: data = 0b01101111;break; // 9
case 10: data = 0b00000000;break; // пусто
case 11: data = 0b01100011;break; // gradus
case 12: data = 0b01110110;break; // H
}
if(n == 0){data0 = data;}
if(n == 1){data1 = data;}
if(n == 2){data2 = data;}
if(n == 3){data3 = data;}
}
switch(pd_t){
case 1 : data2 = data2+0b10000000;break;
case 2 : data1 = data1+0b10000000;break;
case 3 : data0 = data0+0b10000000;break;
}
tm_dec(0xC0);tm_dec(data0);tm_dec(data1);tm_dec(data2);tm_dec(data3);tm_stop();
}
void del(){delayMicroseconds(200);}
Attiny2313+DHT11+LCDNokia3410
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
extern const uint8_t BIG_FONT[] PROGMEM;
const uint8_t BIG_FONT[] PROGMEM = {
0x00,0xF0,0xFC,0xFE,0x06,0x02,0x06,0xFE,0xFC,0xF0,0x00, // 0
0x00,0x07,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x07,0x00,
0x00,0x00,0x08,0x0C,0xFC,0xFE,0xFE,0x00,0x00,0x00,0x00, // 1
0x00,0x20,0x20,0x20,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x00,
0x00,0x0C,0x0E,0x06,0x02,0x02,0x86,0xFE,0x7C,0x38,0x00, // 2
0x00,0x30,0x38,0x3C,0x36,0x33,0x31,0x30,0x30,0x38,0x00,
0x00,0x0C,0x0E,0x86,0x82,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 3
0x00,0x18,0x38,0x30,0x20,0x20,0x31,0x3F,0x1F,0x0E,0x00,
0x00,0x00,0xC0,0x20,0x18,0x04,0xFE,0xFE,0xFE,0x00,0x00, // 4
0x00,0x03,0x02,0x02,0x02,0x22,0x3F,0x3F,0x3F,0x22,0x02,
0x00,0x00,0x7E,0x7E,0x46,0x46,0xC6,0xC6,0x86,0x00,0x00, // 5
0x00,0x18,0x38,0x30,0x20,0x20,0x30,0x3F,0x1F,0x0F,0x00,
0x00,0xC0,0xF0,0xF8,0xFC,0x4C,0xC6,0xC2,0x82,0x00,0x00, // 6
0x00,0x0F,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x0F,0x00,
0x00,0x06,0x06,0x06,0x06,0x06,0xC6,0xF6,0x3E,0x0E,0x00, // 7
0x00,0x00,0x00,0x30,0x3C,0x0F,0x03,0x00,0x00,0x00,0x00,
0x00,0x38,0x7C,0xFE,0xC6,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 8
0x00,0x0E,0x1F,0x3F,0x31,0x20,0x31,0x3F,0x1F,0x0E,0x00,
0x00,0x78,0xFC,0xFE,0x86,0x02,0x86,0xFE,0xFC,0xF8,0x00, // 9
0x00,0x00,0x00,0x21,0x21,0x31,0x1D,0x1F,0x0F,0x03,0x00,
0xF0,0xF8,0x0C,0x06,0x02,0x02,0x02,0x02,0x0E,0x0C,0x00, // C
0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x1C,0x0C,0x00,
0x00,0x06,0x06,0x09,0x09,0x09,0x09,0x06,0x06,0x00,0x00, // degrees
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // degrees
0x00,0x06,0x06,0x09,0x09,0x09,0x09,0x06,0x06,0x00,0x00
};
extern const uint8_t SMALL_FONT[] PROGMEM;
const uint8_t SMALL_FONT[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, // 20
0x00, 0x00, 0x5f, 0x00, 0x00, // 21 !
0x00, 0x07, 0x00, 0x07, 0x00, // 22 "
0x14, 0x7f, 0x14, 0x7f, 0x14, // 23 #
0x24, 0x2a, 0x7f, 0x2a, 0x12, // 24 $
0x23, 0x13, 0x08, 0x64, 0x62, // 25 %
0x36, 0x49, 0x55, 0x22, 0x50, // 26 &
0x00, 0x05, 0x03, 0x00, 0x00, // 27 '
0x00, 0x1c, 0x22, 0x41, 0x00, // 28 (
0x00, 0x41, 0x22, 0x1c, 0x00, // 29 )
0x14, 0x08, 0x3e, 0x08, 0x14, // 2a *
0x08, 0x08, 0x3e, 0x08, 0x08, // 2b +
0x00, 0x50, 0x30, 0x00, 0x00, // 2c ,
0x08, 0x08, 0x08, 0x08, 0x08, // 2d -
0x00, 0x60, 0x60, 0x00, 0x00, // 2e .
0x20, 0x10, 0x08, 0x04, 0x02, // 2f /
0x3e, 0x51, 0x49, 0x45, 0x3e, // 30 0
0x00, 0x42, 0x7f, 0x40, 0x00, // 31 1
0x42, 0x61, 0x51, 0x49, 0x46, // 32 2
0x21, 0x41, 0x45, 0x4b, 0x31, // 33 3
0x18, 0x14, 0x12, 0x7f, 0x10, // 34 4
0x27, 0x45, 0x45, 0x45, 0x39, // 35 5
0x3c, 0x4a, 0x49, 0x49, 0x30, // 36 6
0x01, 0x71, 0x09, 0x05, 0x03, // 37 7
0x36, 0x49, 0x49, 0x49, 0x36, // 38 8
0x06, 0x49, 0x49, 0x29, 0x1e, // 39 9
0x00, 0x36, 0x36, 0x00, 0x00, // 3a :
0x00, 0x56, 0x36, 0x00, 0x00, // 3b ;
0x08, 0x14, 0x22, 0x41, 0x00, // 3c <
0x14, 0x14, 0x14, 0x14, 0x14, // 3d =
0x00, 0x41, 0x22, 0x14, 0x08, // 3e >
0x02, 0x01, 0x51, 0x09, 0x06, // 3f ?
0x32, 0x49, 0x79, 0x41, 0x3e, // 40 @
0x7e, 0x11, 0x11, 0x11, 0x7e, // 41 A
0x7f, 0x49, 0x49, 0x49, 0x36, // 42 B
0x3e, 0x41, 0x41, 0x41, 0x22, // 43 C
0x7f, 0x41, 0x41, 0x22, 0x1c, // 44 D
0x7f, 0x49, 0x49, 0x49, 0x41, // 45 E
0x7f, 0x09, 0x09, 0x09, 0x01, // 46 F
0x3e, 0x41, 0x49, 0x49, 0x7a, // 47 G
0x7f, 0x08, 0x08, 0x08, 0x7f, // 48 H
0x00, 0x41, 0x7f, 0x41, 0x00, // 49 I
0x20, 0x40, 0x41, 0x3f, 0x01, // 4a J
0x7f, 0x08, 0x14, 0x22, 0x41, // 4b K
0x7f, 0x40, 0x40, 0x40, 0x40, // 4c L
0x7f, 0x02, 0x0c, 0x02, 0x7f, // 4d M
0x7f, 0x04, 0x08, 0x10, 0x7f, // 4e N
0x3e, 0x41, 0x41, 0x41, 0x3e, // 4f O
0x7f, 0x09, 0x09, 0x09, 0x06, // 50 P
0x3e, 0x41, 0x51, 0x21, 0x5e, // 51 Q
0x7f, 0x09, 0x19, 0x29, 0x46, // 52 R
0x46, 0x49, 0x49, 0x49, 0x31, // 53 S
0x01, 0x01, 0x7f, 0x01, 0x01, // 54 T
0x3f, 0x40, 0x40, 0x40, 0x3f, // 55 U
0x1f, 0x20, 0x40, 0x20, 0x1f, // 56 V
0x3f, 0x40, 0x38, 0x40, 0x3f, // 57 W
0x63, 0x14, 0x08, 0x14, 0x63, // 58 X
0x07, 0x08, 0x70, 0x08, 0x07, // 59 Y
0x61, 0x51, 0x49, 0x45, 0x43, // 5a Z
0x00, 0x7f, 0x41, 0x41, 0x00, // 5b [
0x02, 0x04, 0x08, 0x10, 0x20, // 5c �
0x00, 0x41, 0x41, 0x7f, 0x00, // 5d ]
0x04, 0x02, 0x01, 0x02, 0x04, // 5e ^
0x40, 0x40, 0x40, 0x40, 0x40, // 5f _
0x00, 0x01, 0x02, 0x04, 0x00, // 60 `
0x20, 0x54, 0x54, 0x54, 0x78, // 61 a
0x7f, 0x48, 0x44, 0x44, 0x38, // 62 b
0x38, 0x44, 0x44, 0x44, 0x20, // 63 c
0x38, 0x44, 0x44, 0x48, 0x7f, // 64 d
0x38, 0x54, 0x54, 0x54, 0x18, // 65 e
0x08, 0x7e, 0x09, 0x01, 0x02, // 66 f
0x0c, 0x52, 0x52, 0x52, 0x3e, // 67 g
0x7f, 0x08, 0x04, 0x04, 0x78, // 68 h
0x00, 0x44, 0x7d, 0x40, 0x00, // 69 i
0x20, 0x40, 0x44, 0x3d, 0x00, // 6a j
0x7f, 0x10, 0x28, 0x44, 0x00, // 6b k
0x00, 0x41, 0x7f, 0x40, 0x00, // 6c l
0x7c, 0x04, 0x18, 0x04, 0x78, // 6d m
0x7c, 0x08, 0x04, 0x04, 0x78, // 6e n
0x38, 0x44, 0x44, 0x44, 0x38, // 6f o
0x7c, 0x14, 0x14, 0x14, 0x08, // 70 p
0x08, 0x14, 0x14, 0x18, 0x7c, // 71 q
0x7c, 0x08, 0x04, 0x04, 0x08, // 72 r
0x48, 0x54, 0x54, 0x54, 0x20, // 73 s
0x04, 0x3f, 0x44, 0x40, 0x20, // 74 t
0x3c, 0x40, 0x40, 0x20, 0x7c, // 75 u
0x1c, 0x20, 0x40, 0x20, 0x1c, // 76 v
0x3c, 0x40, 0x30, 0x40, 0x3c, // 77 w
0x44, 0x28, 0x10, 0x28, 0x44, // 78 x
0x0c, 0x50, 0x50, 0x50, 0x3c, // 79 y
0x44, 0x64, 0x54, 0x4c, 0x44, // 7a z
0x00, 0x08, 0x36, 0x41, 0x00, // 7b {
0x00, 0x00, 0x7f, 0x00, 0x00, // 7c |
0x00, 0x41, 0x36, 0x08, 0x00, // 7d ,
0x10, 0x08, 0x08, 0x10, 0x08, // 7e left arrow
0x78, 0x46, 0x41, 0x46, 0x78, // 7f right arrow
};
// Nokia LCD pin numbers
#define LCD_MOSI PINB2
#define LCD_SCK PINB4
#define LCD_CD PINB1
#define LCD_RESET PINB0
#define DHT PINB3
/** Number of columns */
#define LCD_COL 96
#define LCD_ROW 9
#define DATA_WIDTH 5
#define CHAR_WIDTH (DATA_WIDTH + 1)
byte _hum, _temp;
void sspiOutMSB(uint8_t sck, uint8_t mosi, uint16_t data, uint8_t bits) {
uint16_t mask = (1 << (bits - 1));
uint8_t output = (1 << mosi);
uint8_t clock = (1 << sck);
while(bits) {
// Set data
if(data&mask)
PORTB |= output;
else
PORTB &= ~output;
// Bring the clock high
PORTB |= clock;
// Move to the next bit
mask = mask >> 1;
bits--;
// Bring the clock low again
PORTB &= ~clock;
}
}
void lcdData(uint8_t data) {
// Bring CD high
PORTB |= (1 << LCD_CD);
// Send the data
sspiOutMSB(LCD_SCK, LCD_MOSI, data, 8);
}
void lcdCommand(uint8_t cmd) {
// Bring CD low
PORTB &= ~(1 << LCD_CD);
// Send the data
sspiOutMSB(LCD_SCK, LCD_MOSI, cmd, 8);
}
void lcdInit() {
// Set up the output pins, ensuring they are all 'low' to start
uint8_t val = (1 << LCD_SCK) | (1 << LCD_MOSI) | (1 << LCD_RESET) | (1 << LCD_CD);
PORTB &= ~val;
DDRB |= val;
// Do a hard reset on the LCD
_delay_ms(10);
PORTB |= (1 << LCD_RESET);
// Initialise the LCD
lcdCommand(0x21); // LCD Extended Commands.
lcdCommand(0xA1); // Set LCD Vop (Contrast).
lcdCommand(0x04); // Set Temp coefficent.
lcdCommand(0x14); // LCD bias mode 1:48.
lcdCommand(0x20); // LCD Normal commands
lcdCommand(0x0C); // Normal display, horizontal addressing
}
void lcdClear(bool invert) {
uint8_t fill = invert?0xFF:0x00;
// Set the position
lcdCommand(0x80);
lcdCommand(0x40);
// Fill in the whole display
for(uint16_t index = 0; index < (LCD_COL * LCD_ROW); index++)
lcdData(fill);
}
void lcdPrintBChar(uint8_t row, uint8_t col, uint8_t ch, bool big, bool invert) {
// Set the starting address
const uint8_t *chdata = BIG_FONT + (ch * 22);
for(uint8_t rowused = row; rowused < row+2; rowused++) {
lcdCommand(0x80 | col);
lcdCommand(0x40 | (rowused % LCD_ROW));
// And send the column data
for(uint8_t pixels = 0; pixels < 11; pixels++, chdata++) {
uint8_t data = pgm_read_byte_near(chdata);
//double sized font
lcdData(invert?~data:data);
if (big) lcdData(invert?~data:data);
};
}
// Add the padding byte
if(col < LCD_COL)
lcdData(invert?0xFF:0x00);
}
// Write small character 5x7
void lcdPrintChar(uint8_t row, uint8_t col, uint8_t ch, bool invert) {
// Make sure it is on the screen
if((row>=LCD_ROW)||(col>=LCD_COL))
return;
// If the character is invalid replace it with the '?'
if((ch<0x20)||(ch>0x7f))
ch = '?';
// Set the starting address
lcdCommand(0x80 | col);
lcdCommand(0x40 | (row % LCD_ROW));
// And send the column data
const uint8_t *chdata = SMALL_FONT + ((ch - 0x20) * 5);
for(uint8_t pixels = 0; (pixels < DATA_WIDTH) && (col < LCD_COL); pixels++, col++, chdata++) {
uint8_t data = pgm_read_byte_near(chdata);
lcdData(invert?~data:data);
}
// Add the padding byte
if(col < LCD_COL)
lcdData(invert?0xFF:0x00);
}
// Print text of small fonts
void lcdPrint(uint8_t row, uint8_t col, const char *str, bool invert) {
for(;(*str!='\0')&&(col<LCD_COL);col+=CHAR_WIDTH,str++)
lcdPrintChar(row, col, *str, invert);
}
void setup(){
lcdInit();
lcdClear(0);
}
void loop()
{
const char * my_const_str;
dht_read(&_hum, &_temp);
my_const_str = " TEMPERATURA";
lcdPrint(1, 0, my_const_str, 0);
lcdPrintBChar(2, 22, _temp / 10 % 10, 0, 0);
lcdPrintBChar(2, 34, _temp % 10, 0, 0);
lcdPrintBChar(2, 46, 11, 0, 0);
lcdPrintBChar(2, 56, 10, 0, 0);
my_const_str = " VLAZHNOST";
lcdPrint(4, 0, my_const_str, 0);
lcdPrintBChar(5, 22, _hum / 10 % 10, 0, 0);
lcdPrintBChar(5, 34, _hum % 10, 0, 0);
lcdPrintBChar(5, 46, 11, 0, 0);
my_const_str = "/";
lcdPrint(5, 57, my_const_str, 0);
lcdPrintBChar(5,60, 12, 0, 0);
}
// общая функция опроса датчика
byte dht_read(byte *hum, byte* temp) {
byte data[5];
byte error=dht_start();
if (error) return error;
for (byte i=0; i<5; i++)
{
data[i]=dht_byte();
}
if (data[0]+data[1]+data[2]+data[3]!=data[4]) return 3;
*hum=data[0];
*temp=data[2];
return 0;
}
byte dht_start(){
DDRB|=(1<<DHT);
_delay_ms(20);
DDRB&=~(1<<DHT);
_delay_us(40);
if (PINB&(1<<DHT)) return 1;
_delay_us(80);
if (!(PINB&(1<<DHT))) return 2;
while(PINB&(1<<DHT));
return 0;
}
byte dht_byte(){
byte i=8, byte=0;
while(i--){
while(!(PINB&(1<<DHT)));
_delay_us(40);
if (PINB&(1<<DHT)) {
byte|=(1<<i);
while(PINB&(1<<DHT));
}
}
return byte;
}
С энергосбережением через 15минут(время можно поменять). Кнопка входа в нормальный режим подключается на Reset и Gnd. Запитывается датчик через порт мк.
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
const unsigned long Alarm = 900000; // time - 15 minutes
unsigned long StartTime = 0; // start time
const int Dht = PIND0; // +dht11
extern const uint8_t BIG_FONT[] PROGMEM;
const uint8_t BIG_FONT[] PROGMEM = {
0x00,0xF0,0xFC,0xFE,0x06,0x02,0x06,0xFE,0xFC,0xF0,0x00, // 0
0x00,0x07,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x07,0x00,
0x00,0x00,0x08,0x0C,0xFC,0xFE,0xFE,0x00,0x00,0x00,0x00, // 1
0x00,0x20,0x20,0x20,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x00,
0x00,0x0C,0x0E,0x06,0x02,0x02,0x86,0xFE,0x7C,0x38,0x00, // 2
0x00,0x30,0x38,0x3C,0x36,0x33,0x31,0x30,0x30,0x38,0x00,
0x00,0x0C,0x0E,0x86,0x82,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 3
0x00,0x18,0x38,0x30,0x20,0x20,0x31,0x3F,0x1F,0x0E,0x00,
0x00,0x00,0xC0,0x20,0x18,0x04,0xFE,0xFE,0xFE,0x00,0x00, // 4
0x00,0x03,0x02,0x02,0x02,0x22,0x3F,0x3F,0x3F,0x22,0x02,
0x00,0x00,0x7E,0x7E,0x46,0x46,0xC6,0xC6,0x86,0x00,0x00, // 5
0x00,0x18,0x38,0x30,0x20,0x20,0x30,0x3F,0x1F,0x0F,0x00,
0x00,0xC0,0xF0,0xF8,0xFC,0x4C,0xC6,0xC2,0x82,0x00,0x00, // 6
0x00,0x0F,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x0F,0x00,
0x00,0x06,0x06,0x06,0x06,0x06,0xC6,0xF6,0x3E,0x0E,0x00, // 7
0x00,0x00,0x00,0x30,0x3C,0x0F,0x03,0x00,0x00,0x00,0x00,
0x00,0x38,0x7C,0xFE,0xC6,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 8
0x00,0x0E,0x1F,0x3F,0x31,0x20,0x31,0x3F,0x1F,0x0E,0x00,
0x00,0x78,0xFC,0xFE,0x86,0x02,0x86,0xFE,0xFC,0xF8,0x00, // 9
0x00,0x00,0x00,0x21,0x21,0x31,0x1D,0x1F,0x0F,0x03,0x00,
0xF0,0xF8,0x0C,0x06,0x02,0x02,0x02,0x02,0x0E,0x0C,0x00, // C
0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x1C,0x0C,0x00,
0x00,0x06,0x06,0x09,0x09,0x09,0x09,0x06,0x06,0x00,0x00, // degrees
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // degrees
0x00,0x06,0x06,0x09,0x09,0x09,0x09,0x06,0x06,0x00,0x00
};
extern const uint8_t SMALL_FONT[] PROGMEM;
const uint8_t SMALL_FONT[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, // 20
0x00, 0x00, 0x5f, 0x00, 0x00, // 21 !
0x00, 0x07, 0x00, 0x07, 0x00, // 22 "
0x14, 0x7f, 0x14, 0x7f, 0x14, // 23 #
0x24, 0x2a, 0x7f, 0x2a, 0x12, // 24 $
0x23, 0x13, 0x08, 0x64, 0x62, // 25 %
0x36, 0x49, 0x55, 0x22, 0x50, // 26 &
0x00, 0x05, 0x03, 0x00, 0x00, // 27 '
0x00, 0x1c, 0x22, 0x41, 0x00, // 28 (
0x00, 0x41, 0x22, 0x1c, 0x00, // 29 )
0x14, 0x08, 0x3e, 0x08, 0x14, // 2a *
0x08, 0x08, 0x3e, 0x08, 0x08, // 2b +
0x00, 0x50, 0x30, 0x00, 0x00, // 2c ,
0x08, 0x08, 0x08, 0x08, 0x08, // 2d -
0x00, 0x60, 0x60, 0x00, 0x00, // 2e .
0x20, 0x10, 0x08, 0x04, 0x02, // 2f /
0x3e, 0x51, 0x49, 0x45, 0x3e, // 30 0
0x00, 0x42, 0x7f, 0x40, 0x00, // 31 1
0x42, 0x61, 0x51, 0x49, 0x46, // 32 2
0x21, 0x41, 0x45, 0x4b, 0x31, // 33 3
0x18, 0x14, 0x12, 0x7f, 0x10, // 34 4
0x27, 0x45, 0x45, 0x45, 0x39, // 35 5
0x3c, 0x4a, 0x49, 0x49, 0x30, // 36 6
0x01, 0x71, 0x09, 0x05, 0x03, // 37 7
0x36, 0x49, 0x49, 0x49, 0x36, // 38 8
0x06, 0x49, 0x49, 0x29, 0x1e, // 39 9
0x00, 0x36, 0x36, 0x00, 0x00, // 3a :
0x00, 0x56, 0x36, 0x00, 0x00, // 3b ;
0x08, 0x14, 0x22, 0x41, 0x00, // 3c <
0x14, 0x14, 0x14, 0x14, 0x14, // 3d =
0x00, 0x41, 0x22, 0x14, 0x08, // 3e >
0x02, 0x01, 0x51, 0x09, 0x06, // 3f ?
0x32, 0x49, 0x79, 0x41, 0x3e, // 40 @
0x7e, 0x11, 0x11, 0x11, 0x7e, // 41 A
0x7f, 0x49, 0x49, 0x49, 0x36, // 42 B
0x3e, 0x41, 0x41, 0x41, 0x22, // 43 C
0x7f, 0x41, 0x41, 0x22, 0x1c, // 44 D
0x7f, 0x49, 0x49, 0x49, 0x41, // 45 E
0x7f, 0x09, 0x09, 0x09, 0x01, // 46 F
0x3e, 0x41, 0x49, 0x49, 0x7a, // 47 G
0x7f, 0x08, 0x08, 0x08, 0x7f, // 48 H
0x00, 0x41, 0x7f, 0x41, 0x00, // 49 I
0x20, 0x40, 0x41, 0x3f, 0x01, // 4a J
0x7f, 0x08, 0x14, 0x22, 0x41, // 4b K
0x7f, 0x40, 0x40, 0x40, 0x40, // 4c L
0x7f, 0x02, 0x0c, 0x02, 0x7f, // 4d M
0x7f, 0x04, 0x08, 0x10, 0x7f, // 4e N
0x3e, 0x41, 0x41, 0x41, 0x3e, // 4f O
0x7f, 0x09, 0x09, 0x09, 0x06, // 50 P
0x3e, 0x41, 0x51, 0x21, 0x5e, // 51 Q
0x7f, 0x09, 0x19, 0x29, 0x46, // 52 R
0x46, 0x49, 0x49, 0x49, 0x31, // 53 S
0x01, 0x01, 0x7f, 0x01, 0x01, // 54 T
0x3f, 0x40, 0x40, 0x40, 0x3f, // 55 U
0x1f, 0x20, 0x40, 0x20, 0x1f, // 56 V
0x3f, 0x40, 0x38, 0x40, 0x3f, // 57 W
0x63, 0x14, 0x08, 0x14, 0x63, // 58 X
0x07, 0x08, 0x70, 0x08, 0x07, // 59 Y
0x61, 0x51, 0x49, 0x45, 0x43, // 5a Z
0x00, 0x7f, 0x41, 0x41, 0x00, // 5b [
0x02, 0x04, 0x08, 0x10, 0x20, // 5c �
0x00, 0x41, 0x41, 0x7f, 0x00, // 5d ]
0x04, 0x02, 0x01, 0x02, 0x04, // 5e ^
0x40, 0x40, 0x40, 0x40, 0x40, // 5f _
0x00, 0x01, 0x02, 0x04, 0x00, // 60 `
0x20, 0x54, 0x54, 0x54, 0x78, // 61 a
0x7f, 0x48, 0x44, 0x44, 0x38, // 62 b
0x38, 0x44, 0x44, 0x44, 0x20, // 63 c
0x38, 0x44, 0x44, 0x48, 0x7f, // 64 d
0x38, 0x54, 0x54, 0x54, 0x18, // 65 e
0x08, 0x7e, 0x09, 0x01, 0x02, // 66 f
0x0c, 0x52, 0x52, 0x52, 0x3e, // 67 g
0x7f, 0x08, 0x04, 0x04, 0x78, // 68 h
0x00, 0x44, 0x7d, 0x40, 0x00, // 69 i
0x20, 0x40, 0x44, 0x3d, 0x00, // 6a j
0x7f, 0x10, 0x28, 0x44, 0x00, // 6b k
0x00, 0x41, 0x7f, 0x40, 0x00, // 6c l
0x7c, 0x04, 0x18, 0x04, 0x78, // 6d m
0x7c, 0x08, 0x04, 0x04, 0x78, // 6e n
0x38, 0x44, 0x44, 0x44, 0x38, // 6f o
0x7c, 0x14, 0x14, 0x14, 0x08, // 70 p
0x08, 0x14, 0x14, 0x18, 0x7c, // 71 q
0x7c, 0x08, 0x04, 0x04, 0x08, // 72 r
0x48, 0x54, 0x54, 0x54, 0x20, // 73 s
0x04, 0x3f, 0x44, 0x40, 0x20, // 74 t
0x3c, 0x40, 0x40, 0x20, 0x7c, // 75 u
0x1c, 0x20, 0x40, 0x20, 0x1c, // 76 v
0x3c, 0x40, 0x30, 0x40, 0x3c, // 77 w
0x44, 0x28, 0x10, 0x28, 0x44, // 78 x
0x0c, 0x50, 0x50, 0x50, 0x3c, // 79 y
0x44, 0x64, 0x54, 0x4c, 0x44, // 7a z
0x00, 0x08, 0x36, 0x41, 0x00, // 7b {
0x00, 0x00, 0x7f, 0x00, 0x00, // 7c |
0x00, 0x41, 0x36, 0x08, 0x00, // 7d ,
0x10, 0x08, 0x08, 0x10, 0x08, // 7e left arrow
0x78, 0x46, 0x41, 0x46, 0x78, // 7f right arrow
};
// Nokia LCD pin numbers
#define LCD_MOSI PINB2
#define LCD_SCK PINB4
#define LCD_CD PINB1
#define LCD_RESET PINB0
#define DHT PINB3
/** Number of columns */
#define LCD_COL 96
#define LCD_ROW 9
#define DATA_WIDTH 5
#define CHAR_WIDTH (DATA_WIDTH + 1)
byte _hum, _temp;// переменные для влажности и температуры
void sspiOutMSB(uint8_t sck, uint8_t mosi, uint16_t data, uint8_t bits) {
uint16_t mask = (1 << (bits - 1));
uint8_t output = (1 << mosi);
uint8_t clock = (1 << sck);
while(bits) {
// Set data
if(data&mask)
PORTB |= output;
else
PORTB &= ~output;
// Bring the clock high
PORTB |= clock;
// Move to the next bit
mask = mask >> 1;
bits--;
// Bring the clock low again
PORTB &= ~clock;
}
}
void lcdData(uint8_t data) {
// Bring CD high
PORTB |= (1 << LCD_CD);
// Send the data
sspiOutMSB(LCD_SCK, LCD_MOSI, data, 8);
}
void lcdCommand(uint8_t cmd) {
// Bring CD low
PORTB &= ~(1 << LCD_CD);
// Send the data
sspiOutMSB(LCD_SCK, LCD_MOSI, cmd, 8);
}
void lcdInit() {
// Set up the output pins, ensuring they are all 'low' to start
uint8_t val = (1 << LCD_SCK) | (1 << LCD_MOSI) | (1 << LCD_RESET) | (1 << LCD_CD);
PORTB &= ~val;
DDRB |= val;
// Do a hard reset on the LCD
_delay_ms(10);
PORTB |= (1 << LCD_RESET);
// Initialise the LCD
lcdCommand(0x21); // LCD Extended Commands.
lcdCommand(0xA1); // Set LCD Vop (Contrast).
lcdCommand(0x04); // Set Temp coefficent.
lcdCommand(0x14); // LCD bias mode 1:48.
lcdCommand(0x20); // LCD Normal commands
lcdCommand(0x0C); // Normal display, horizontal addressing
}
void lcdClear(bool invert) {
uint8_t fill = invert?0xFF:0x00;
// Set the position
lcdCommand(0x80);
lcdCommand(0x40);
// Fill in the whole display
for(uint16_t index = 0; index < (LCD_COL * LCD_ROW); index++)
lcdData(fill);
}
void lcdPrintBChar(uint8_t row, uint8_t col, uint8_t ch, bool big, bool invert) {
// Set the starting address
const uint8_t *chdata = BIG_FONT + (ch * 22);
for(uint8_t rowused = row; rowused < row+2; rowused++) {
lcdCommand(0x80 | col);
lcdCommand(0x40 | (rowused % LCD_ROW));
// And send the column data
for(uint8_t pixels = 0; pixels < 11; pixels++, chdata++) {
uint8_t data = pgm_read_byte_near(chdata);
//double sized font
lcdData(invert?~data:data);
if (big) lcdData(invert?~data:data);
};
}
// Add the padding byte
if(col < LCD_COL)
lcdData(invert?0xFF:0x00);
}
// Write small character 5x7
void lcdPrintChar(uint8_t row, uint8_t col, uint8_t ch, bool invert) {
// Make sure it is on the screen
if((row>=LCD_ROW)||(col>=LCD_COL))
return;
// If the character is invalid replace it with the '?'
if((ch<0x20)||(ch>0x7f))
ch = '?';
// Set the starting address
lcdCommand(0x80 | col);
lcdCommand(0x40 | (row % LCD_ROW));
// And send the column data
const uint8_t *chdata = SMALL_FONT + ((ch - 0x20) * 5);
for(uint8_t pixels = 0; (pixels < DATA_WIDTH) && (col < LCD_COL); pixels++, col++, chdata++) {
uint8_t data = pgm_read_byte_near(chdata);
lcdData(invert?~data:data);
}
// Add the padding byte
if(col < LCD_COL)
lcdData(invert?0xFF:0x00);
}
// Print text of small fonts
void lcdPrint(uint8_t row, uint8_t col, const char *str, bool invert) {
for(;(*str!='\0')&&(col<LCD_COL);col+=CHAR_WIDTH,str++)
lcdPrintChar(row, col, *str, invert);
}
void setup(){
DDRD|=(1<<Dht);
PORTD = PORTD | 1<<Dht;
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
lcdInit();
lcdClear(0);
}
void loop()
{
const char * my_const_str;
do{
// const char * my_const_str;
dht_read(&_hum, &_temp);
my_const_str = " TEMPERATURA";
lcdPrint(1, 0, my_const_str, 0);
lcdPrintBChar(2, 22, _temp / 10 % 10, 0, 0);
lcdPrintBChar(2, 34, _temp % 10, 0, 0);
lcdPrintBChar(2, 46, 11, 0, 0);
lcdPrintBChar(2, 56, 10, 0, 0);
my_const_str = " VLAZHNOST";
lcdPrint(4, 0, my_const_str, 0);
lcdPrintBChar(5, 22, _hum / 10 % 10, 0, 0);
lcdPrintBChar(5, 34, _hum % 10, 0, 0);
lcdPrintBChar(5, 46, 11, 0, 0);
my_const_str = "/";
lcdPrint(5, 57, my_const_str, 0);
lcdPrintBChar(5,60, 12, 0, 0);
}
while( millis() - StartTime < Alarm);
lcdClear(0);
my_const_str = " SLEEP MODE";
lcdPrint(2, 0, my_const_str, 0);
my_const_str = " PRESS BUTTON";
lcdPrint(4, 0, my_const_str, 0);
PORTD = PORTD & ~(1<<Dht);
sleep_enable();
sleep_cpu();
}
byte dht_read(byte *hum, byte* temp) {
byte data[5];
byte error=dht_start();
if (error) return error;
for (byte i=0; i<5; i++)
{
data[i]=dht_byte();
}
if (data[0]+data[1]+data[2]+data[3]!=data[4]) return 3;
*hum=data[0];
*temp=data[2];
return 0;
}
byte dht_start(){
DDRB|=(1<<DHT);
_delay_ms(20);
DDRB&=~(1<<DHT);
_delay_us(40);
if (PINB&(1<<DHT)) return 1;
_delay_us(80);
if (!(PINB&(1<<DHT))) return 2;
while(PINB&(1<<DHT));
return 0;
}
byte dht_byte(){
byte i=8, byte=0;
while(i--){
while(!(PINB&(1<<DHT)));
_delay_us(40);
if (PINB&(1<<DHT)) {
byte|=(1<<i);
while(PINB&(1<<DHT));
}
}
return byte;
}
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
forum.rcl-radio.ru → Переделки → ATtiny2313 + DHT11 (Arduino IDE)
Форум работает на PunBB, при поддержке Informer Technologies, Inc
|