Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * LAB3_C.c
- *
- * Created: 31-01-2019 11:11:36
- * Author : HBIND
- */
- #define F_CPU 16000000
- #include "lcd162.h"
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- void Init_ADC();
- void Init_Timer1();
- void test_program();
- int main(void)
- {
- /* Replace with your application code */
- LCDInit();
- LCDOnOffControl(0, 1);
- Init_ADC();
- Init_Timer1();
- sei();
- test_program();
- while (1)
- {
- }
- }
- void test_program()
- {
- LCDDispString("Let's test:");
- _delay_ms(2000);
- LCDGotoXY(0,1);
- LCDDispString("DispChar: ");
- LCDDispChar('G');
- _delay_ms(1000);
- LCDGotoXY(0,1);
- LCDDispString("DispInt: ");
- LCDDispInteger(46);
- _delay_ms(1000);
- LCDGotoXY(0,1);
- LCDDispString("Blink/cursor:");
- LCDOnOffControl(1, 0);
- _delay_ms(1000);
- LCDOnOffControl(0, 1);
- _delay_ms(1000);
- LCDGotoXY(0,1);
- LCDDispString("Shift Screen:");
- LCDShiftRight();
- _delay_ms(1000);
- LCDShiftLeft();
- _delay_ms(1000);
- LCDGotoXY(0,1);
- LCDDispString("Move Cursor: ");
- LCDCursorRight();
- _delay_ms(1000);
- LCDCursorLeft();
- _delay_ms(1000);
- _delay_ms(5000);
- LCDClear();
- }
- void Init_ADC()
- {
- // PF pins are inputs (ADC7-ADC0)
- DDRF = 0;
- // Internal 5 volt reference, ADLAR = 0, Input = ADC0 single ended (potentiometer)
- ADMUX = 0b01000000;
- // ADC enable
- // ADC interrupt enabled
- // Automatic start enabled
- // ADC prescaler = 128 (=> ADC clock = 16 MHz / 128 = 125 kHZ)
- ADCSRA = 0b10101111;
- // Auto trigger source = Timer 1 overflow
- ADCSRB = 0b00000110;
- }
- void Init_Timer1()
- {
- // 16000000 Hz /64 = 250 kHz
- // Therefore we have 250000 "steps" per second
- // - and want 0,25 seconds until next overflow
- TCNT1 = 65536-62500;
- // Timer 1 in Normal Mode and PS = 64
- TCCR1A = 0b00000000;
- TCCR1B = 0b00000011;
- // Enable Timer 1 overflow interrupts
- TIMSK1 |= 0b00000001;
- }
- ISR(TIMER1_OVF_vect)
- {
- //Reload Timer 1: 0,25 seconds to next overflow
- TCNT1 = 65536-62500;
- }
- ISR(ADC_vect)
- {
- readKeys();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement