Instantly share code, notes, and snippets.
Last active
October 16, 2023 17:24
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save gammels/93ca7790e21790c8878180ef908f4914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* lcd_menu_xxxxx.c | |
* | |
* Created: 2014-08-10 18:00:00 | |
* Author: Gammels | |
*/ | |
#include <util/delay.h> | |
#include <avr/io.h> | |
#include <stdlib.h> | |
#include <user/menu_dsp.h> | |
#include <user/lcd44780.h> | |
//#include <user/buttons_rs.h> | |
//#include <util/atomic.h> | |
//#include <avr/interrupt.h> | |
#define F_CPU 16000000UL | |
//#define Vref 2.56 | |
//#define button_number 4 | |
//char Pressed[button_number]; | |
//int Pressed_Conf_Level[button_number]; // Zmienna określająca wciśnięcie przycisku | |
//int Released_Conf_Level[button_number]; // Zmienna określająca zwolnienie przycisku | |
//int Conf_Level; | |
//char adcResult[5]; // char oznacza typ całkowity (liczba całkowita w zakresie) | |
//float Vin; | |
int main() // program główny | |
{ | |
//DDRC |= 1<<PINC0; | |
//PORTC = 1<<PINC0; | |
_delay_ms(20); | |
InitializeLCD_On(); | |
_delay_ms(20); | |
booting_lcd(); | |
clear_LCD_scr(); | |
while | |
( | |
Shift_LA(); | |
GotoLocation(1,1); | |
Send_A_String(""); | |
) | |
} | |
//ADMUX |= 1<<MUX0 | 0<<MUX0; // Konfiguracja ADC PINA1 adc1 | |
//ADMUX |= 1<<ADPS2; // Włączenie preskalera (16)- oznaczony przez wewnętrzny lub zewnętrzny zegar 50kHz- 200kHz >> 1000000/50000=20 1000000/200000=5 >>> 8 lub 16 | |
//ADMUX |= 1<<ADLAR; // Rezultat 8-bitowy lub 10-bitowy | |
//ADMUX |= 1<<REFS0 | 1<<REFS1; // Ustawienie Vref na AVCC 11 -> 2.56V | |
//ADCSRA |= 1<<ADIE; // Włączenie funkcji przerwań w ADC | |
//ADCSRA |= 1<<ADEN; // Włączenie funkcji ADC | |
//sei(); // Włączenie przerwań globalnych | |
//ADCSRA |= 1<<ADSC; // Start pierwszej konwersji | |
/* | |
ISR(ADC_vect) | |
{ | |
uint8_t theLow = ADCL; // deklaracja zmiennej na wyświetlaczu | |
int16_t tenBitValue = ADCH<<4 | theLow>>6; // wartości ADCH odpowiadają dokładności 2 >1024; 3>2040; 4>4080; ...; 8>(0 do -200) | |
Vin=tenBitValue*Vref/2048; // przelicznik bitów na wolty | |
dtostrf(Vin,0.0001,2,adcResult); // convert the ADC conversion result digtostring(z,precyzja, ilość miejsca po przecinku,bufor) page 114 | |
GotoLocation(7,1); | |
Send_A_String(adcResult); | |
Send_A_String(" "); | |
menu_1(); | |
_delay_ms(7); | |
buttons_val_conversion(); // biblioteka buttons_rs | |
disp_val_buttons_in_position(7,2); // biblioteka buttons_rs | |
if ((Vdc>(KEY_1-KEY_ERROR)) && (Vdc<(KEY_1+KEY_ERROR))) | |
{ | |
sleep_lcd(); | |
PORTC = 0<<PINC0; | |
} | |
if ((Vdc>(KEY_1-KEY_ERROR)) && (Vdc<(KEY_1+KEY_ERROR)) && (PINC0 == 1)) | |
{ | |
PORTC = 1<<PINC0; | |
wake_up_lcd(); | |
} | |
/* | |
char ButtonPressed_1(int button_number, int Conf_Level) | |
{ | |
Pressed_Conf_Level[button_number] ++; // Increase Pressed conficence | |
Released_Conf_Level[button_number] = 0; // Reset relased button confidence since the button is relased | |
if(Pressed_Conf_Level[button_number] > Conf_Level ) // 200 oznacza że jest wiecej niż 200x | |
{ | |
if(Pressed[button_number] == 0) | |
{ | |
Pressed[button_number] = 1; | |
return 1; | |
} | |
Pressed_Conf_Level[button_number] = 0; // Zero it so a new pressed condition can be evaluated | |
} | |
else | |
{ | |
Released_Conf_Level[button_number] ++; // This work just like the pressed | |
Pressed_Conf_Level[button_number] = 0; // Reset pressed button confidence since the button is relased | |
if(Released_Conf_Level[button_number] > Conf_Level ) // 200 oznacza że jest wiecej niż 200x | |
{ | |
Pressed[button_number] = 0; | |
Released_Conf_Level[button_number] = 0; | |
} | |
} | |
return 0; | |
} | |
} | |
*/ | |
/* | |
if ((Vdc>(KEY_2-KEY_ERROR)) && (Vdc<(KEY_2+KEY_ERROR))) | |
{ | |
PORTC =1<<PINC0; | |
wake_up_lcd(); | |
} | |
ADCSRA |= 1<<ADSC; | |
} | |
switch (ADMUX) //ADMUX zmienna kanałów ADC | |
{ | |
case 0xC0: | |
Vin=BitValue*Vref/1024; | |
dtostrf(Vin,0.002,3,adcResult); // Convert the ADC conversion result digtostring(z,precyzja,ilość miejsca po przecinku,bufor) page 114 | |
GotoLocation(4,1); | |
Send_A_String(adcResult); | |
ADMUX = 0xC1; // Przełącza na drugi kanał po zakończeniu operacji | |
break; | |
case 0xC1: | |
Vin=BitValue*Vref/1024; | |
dtostrf(Vin,0.002,3,adcResult); // Convert the ADC conversion result digtostring(z,precyzja,ilość miejsca po przecinku,bufor) page 114 | |
GotoLocation(4,2); | |
Send_A_String(adcResult); | |
ADMUX = 0xC2; // Przełącza na drugi kanał po zakończeniu operacji | |
break; | |
case 0xC2: | |
Vin=BitValue*Vref/1024; | |
dtostrf(Vin,0.002,3,adcResult); // Convert the ADC conversion result digtostring(z,precyzja,ilość miejsca po przecinku,bufor) page 114 | |
GotoLocation(12,1); | |
Send_A_String(adcResult); | |
ADMUX = 0xC4; // Przełącza na drugi kanał po zakończeniu operacji | |
break; | |
case 0xC4: | |
Vin=BitValue*Vref/1024; | |
dtostrf(Vin,0.002,3,adcResult); // Convert the ADC conversion result digtostring(z,precyzja,ilość miejsca po przecinku,bufor) page 114 | |
GotoLocation(12,2); | |
Send_A_String(adcResult); | |
ADMUX = 0xC0; // Przełącza na drugi kanał po zakończeniu operacji | |
break; | |
default: | |
//default code | |
break; | |
} | |
/* | |
if ((Vdc>(KEY_1-KEY_ERROR)) && (Vdc<(KEY_1+KEY_ERROR))) | |
{ | |
GotoLocation(11,2); | |
Send_A_String("KEY_1"); | |
Send_A_String(" "); | |
} | |
else | |
{ | |
GotoLocation(11,2); | |
Send_A_String(" "); | |
} | |
ATOMIC_BLOCK(ATOMIC_FORCEON) | |
{ | |
DDRC |= 1<<PINC7 | 1<<PINC6; | |
if ((Vdc>(KEY_1-KEY_ERROR)) && (Vdc<(KEY_1+KEY_ERROR))) | |
{ | |
PORTC = 1<<PIN7; | |
GotoLocation(11,2); | |
Send_A_String("KEY_1"); | |
Send_A_String(" "); | |
_delay_ms(10); | |
PORTC = 0<<PIN7; | |
} | |
else | |
{ | |
GotoLocation(11,2); | |
Send_A_String(" "); | |
} | |
if ((Vdc>(KEY_2-KEY_ERROR)) && (Vdc<(KEY_2+KEY_ERROR))) | |
{ | |
PORTC = 1<<PIN6; | |
GotoLocation(11,2); | |
Send_A_String("KEY_2"); | |
Send_A_String(" "); | |
_delay_ms(10); | |
PORTC = 0<<PIN6; | |
} | |
else | |
{ | |
GotoLocation(11,2); | |
Send_A_String(" "); | |
} | |
if ((Vdc>(KEY_3-KEY_ERROR)) && (Vdc<(KEY_3+KEY_ERROR))) | |
{ | |
GotoLocation(11,2); | |
Send_A_String("KEY_3"); | |
Send_A_String(" "); | |
_delay_ms(10); | |
} | |
else | |
{ | |
GotoLocation(11,2); | |
Send_A_String(" "); | |
} | |
if ((Vdc>(KEY_4-KEY_ERROR)) && (Vdc<(KEY_4+KEY_ERROR))) | |
{ | |
GotoLocation(11,2); | |
Send_A_String("KEY_4"); | |
Send_A_String(" "); | |
_delay_ms(10); | |
} | |
else | |
{ | |
GotoLocation(11,2); | |
Send_A_String(" "); | |
} | |
if ((Vdc>(NOKEY-KEY_ERROR)) && (Vdc<(NOKEY+KEY_ERROR))) | |
{ | |
_delay_ms(5); | |
GotoLocation(11,1); | |
Send_A_String("NO_KEY"); | |
Send_A_String(" "); | |
} | |
else | |
{ | |
GotoLocation(11,1); | |
Send_A_String(" "); | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment