Advertisement
Alx09

var bun

Oct 15th, 2021
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 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.   adc_init();
  23.   Afis();
  24. }
  25. void Print0(unsigned short nr){
  26.  if(nr < 10) lcd.print('0');
  27. }
  28. void Afis(){
  29.    
  30.   lcd.setCursor(0,0);
  31.   lcd.print("Ora:");
  32.   Print0(ore);
  33.   lcd.print(ore);
  34.   lcd.print(':');
  35.   Print0(minute);
  36.   lcd.print(minute);
  37.   lcd.print(':');
  38.   Print0(secunde);
  39.   lcd.print(secunde);
  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. }
  49. void loop(){
  50.  
  51.  
  52.    
  53. }
  54. ISR(TIMER2_OVF_vect){
  55.    ++nrInterrupts;
  56.   if(nrInterrupts == 61){
  57.      
  58.    ++secunde;
  59.   nrInterrupts = 0;
  60.   if(secunde > 59){
  61.     ++minute;
  62.     secunde = 0;
  63.   }
  64.   if(minute > 59){
  65.    ++ore;
  66.     minute = 0;
  67.   }
  68.   if(ore == 24)
  69.     ore = 0;
  70.     Afis();
  71.   }  
  72. }
  73. void adc_init() //adc initialization
  74. {
  75.   //set division factor between system clock frequency and the input clock to the ADC- 128
  76.   ADCSRA |= ((1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0));
  77.   ADMUX|=(1<<REFS0); //AVcc with external capacitor at Aref pin
  78.   ADCSRA|=(1<<ADEN); //enable ADC
  79.   ADCSRA|=(1<<ADSC); //ADC start conversion
  80. }
  81.  
  82. uint16_t read_adc(uint8_t channel)
  83. {
  84.   ADMUX&=0xF0; //set input AO to A5
  85.   ADMUX|=channel; //select chanel AO to A5
  86.   ADCSRA|=(1<<ADSC); //start conversion
  87.   while(ADCSRA & (1<<ADSC)); //wait while adc conversion are not updated
  88.   return ADCW; //read and return voltage
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement