This shows you the differences between two versions of the page.
| et:exercises:sensor:photoresistor:aplha [2012/04/05 09:16] – tekitatud raivo.sell | et:exercises:sensor:photoresistor:aplha [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Alfabeetilise LCD koodi näide ====== | ||
| + | <code c> | ||
| + | // | ||
| + | // Kodulabori Andurite mooduli fototakisti näidisprogramm. | ||
| + | // LCD ekraanil kuvatakse ligikaudne valgustustihedus luksides | ||
| + | // | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // | ||
| + | // Põhiprogramm | ||
| + | // | ||
| + | int main(void) | ||
| + | { | ||
| + | char text[16]; | ||
| + | unsigned short adc_value; | ||
| + | double voltage, resistance, illuminance; | ||
| + | |||
| + | // LCD ekraani seadistamine | ||
| + | lcd_alpha_init(LCD_ALPHA_DISP_ON); | ||
| + | |||
| + | // LCD ekraani puhastamine | ||
| + | lcd_alpha_clear(); | ||
| + | |||
| + | // Programmi nimi | ||
| + | lcd_alpha_write_string(" | ||
| + | |||
| + | // ADC muunduri seadistamine | ||
| + | adc_init(ADC_REF_AVCC, | ||
| + | |||
| + | // Lõputu tsükkel | ||
| + | while (true) | ||
| + | { | ||
| + | // Fototakisti keskmistatud väärtuse lugemine | ||
| + | adc_value = adc_get_average_value(1, | ||
| + | |||
| + | // Pinge arvutamine ADC sisendis | ||
| + | voltage = 5.0 * ((double)adc_value / 1024.0); | ||
| + | |||
| + | // Fototakisti takistuse arvutamine pingejaguris | ||
| + | resistance = (10.0 * 5.0) / voltage - 10.0; | ||
| + | |||
| + | // Valgustustiheduse luksides arvutamine | ||
| + | illuminance = 255.84 * pow(resistance, | ||
| + | |||
| + | // Valgustustiheduse tekstiks teisendamine | ||
| + | sprintf(text, | ||
| + | |||
| + | // Näidu LCD-l kuvamine | ||
| + | lcd_alpha_goto_xy(0, | ||
| + | lcd_alpha_write_string(text); | ||
| + | |||
| + | // Viide 500 ms | ||
| + | sw_delay_ms(500); | ||
| + | } | ||
| + | } | ||
| + | </ | ||