Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- unsigned short secunde=0, miliSecunde=0, minute=40, ore=15;
- unsigned char nrInterrupts;
- unsigned int numar_CAN;
- int voltageValue, temperatureRead;
- unsigned int temp;
- void setup()
- {
- DDRD |= 0xFF;
- DDRB|=0x03;
- lcd.begin(0, 2);
- TIMSK2 = 0x01; // validare intrerupere de la Timer 0 Overflow
- TCCR2A = 0x00; // setare mod normal
- TCCR2B = 0x07;
- /////
- DDRC&=~0x10;
- DDRD=B00001111;
- adc_init();
- Afis();
- }
- void Print0(unsigned short nr){
- if(nr < 10) lcd.print('0');
- }
- void Afis(){
- lcd.setCursor(0,0);
- lcd.print("Ora:");
- Print0(ore);
- lcd.print(ore);
- lcd.print(':');
- Print0(minute);
- lcd.print(minute);
- lcd.print(':');
- Print0(secunde);
- lcd.print(secunde);
- lcd.setCursor(0,1);
- numar_CAN=read_adc(4);
- temp=read_adc(5);
- voltageValue=(temp*5000.0)/1024.0;
- temperatureRead=(voltageValue-500)/10;
- lcd.print("Temp = ");
- lcd.print(temperatureRead);
- lcd.print(" 'C");
- }
- void loop(){
- }
- ISR(TIMER2_OVF_vect){
- ++nrInterrupts;
- if(nrInterrupts == 61){
- ++secunde;
- nrInterrupts = 0;
- if(secunde > 59){
- ++minute;
- secunde = 0;
- }
- if(minute > 59){
- ++ore;
- minute = 0;
- }
- if(ore == 24)
- ore = 0;
- Afis();
- }
- }
- void adc_init() //adc initialization
- {
- //set division factor between system clock frequency and the input clock to the ADC- 128
- ADCSRA |= ((1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0));
- ADMUX|=(1<<REFS0); //AVcc with external capacitor at Aref pin
- ADCSRA|=(1<<ADEN); //enable ADC
- ADCSRA|=(1<<ADSC); //ADC start conversion
- }
- uint16_t read_adc(uint8_t channel)
- {
- ADMUX&=0xF0; //set input AO to A5
- ADMUX|=channel; //select chanel AO to A5
- ADCSRA|=(1<<ADSC); //start conversion
- while(ADCSRA & (1<<ADSC)); //wait while adc conversion are not updated
- return ADCW; //read and return voltage
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement