Advertisement
Alx09

sadas

Oct 15th, 2021
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.97 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
  4. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  5. unsigned short secunde=0, miliSecunde=0, minute=40, ore=15;
  6. unsigned char nrInterrupts;
  7.  
  8. unsigned int numar_CAN;
  9. int voltageValue, temperatureRead;
  10. unsigned int temp;
  11. void setup()
  12. {
  13.   DDRD |= 0xFF;
  14.   DDRB|=0x03;
  15.   lcd.begin(0, 2);
  16.   TIMSK2 = 0x01; // validare intrerupere de la Timer 0 Overflow
  17.   TCCR2A = 0x00; // setare mod normal
  18.   TCCR2B = 0x07;
  19.   /////
  20.   DDRC&=~0x10;
  21.   DDRD=B00001111;
  22. }
  23. void Print0(unsigned short nr){
  24.  if(nr < 10) lcd.print('0');
  25. }
  26. void loop(){
  27.   lcd.clear();
  28.   lcd.setCursor(0,0);
  29.   lcd.print("Ora:");
  30.   Print0(ore);
  31.   lcd.print(ore);
  32.   lcd.print(':');
  33.   Print0(minute);
  34.   lcd.print(minute);
  35.   lcd.print(':');
  36.   Print0(secunde);
  37.   lcd.print(secunde);
  38.   delay(1000);
  39.      adc_init();
  40.      lcd.setCursor(0,1);
  41.      numar_CAN=read_adc(4);
  42.      temp=read_adc(5);
  43.      voltageValue=(temp*5000.0)/1024.0;
  44.      temperatureRead=(voltageValue-500)/10;
  45.      lcd.print("Temp=");
  46.      lcd.print(temperatureRead);
  47.      lcd.print("'C");
  48.      delay(100);
  49. }
  50. ISR(TIMER2_OVF_vect){
  51.    ++nrInterrupts;
  52.   if(nrInterrupts == 61){
  53.    ++secunde;
  54.   nrInterrupts = 0;
  55.   if(secunde > 59){
  56.     ++minute;
  57.     secunde = 0;
  58.   }
  59.   if(minute > 59){
  60.    ++ore;
  61.     minute = 0;
  62.   }
  63.   if(ore == 24)
  64.     ore = 0;
  65.   }  
  66. }
  67. void adc_init() //adc initialization
  68. {
  69.   //set division factor between system clock frequency and the input clock to the ADC- 128
  70.   ADCSRA |= ((1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0));
  71.   ADMUX|=(1<<REFS0); //AVcc with external capacitor at Aref pin
  72.   ADCSRA|=(1<<ADEN); //enable ADC
  73.   ADCSRA|=(1<<ADSC); //ADC start conversion
  74. }
  75.  
  76. uint16_t read_adc(uint8_t channel)
  77. {
  78.   ADMUX&=0xF0; //set input AO to A5
  79.   ADMUX|=channel; //select chanel AO to A5
  80.   ADCSRA|=(1<<ADSC); //start conversion
  81.   while(ADCSRA & (1<<ADSC)); //wait while adc conversion are not updated
  82.   return ADCW; //read and return voltage
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement