Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * AVRGCC1.c
- *
- * Created: 2018-04-05 13:32:26
- * Author: student
- */
- #include <avr/io.h>
- #define F_CPU 16000000UL
- #include <util/delay.h>
- #include <lcd.h>
- void lcd_reset()
- {
- COMM_LCD = 0x02;
- test_bf();
- }
- void lcd_clear()
- {
- COMM_LCD = 0x01;
- test_bf();
- }
- void lcd_init(void)
- {
- _delay_ms(20);
- COMM_LCD = 0x30;
- _delay_ms(5);
- COMM_LCD = 0x30;
- _delay_ms(1);
- COMM_LCD = 0x30;
- _delay_ms(30);
- COMM_LCD = 0x38;
- test_bf();
- COMM_LCD = 0x0C;
- test_bf();
- lcd_clear();
- COMM_LCD = 0x06;
- test_bf();
- lcd_reset();
- // clear charrow
- for (int i = 0; i < 64; i++) {
- COMM_LCD = 0x40 | i;
- test_bf();
- DATA_LCD = 0;
- test_bf();
- }
- }
- void extram_init(void)
- {
- MCUCR = _BV(SRE) | _BV(SRW10);
- XMCRA = _BV(SRW00) | _BV(SRW01) | _BV(SRW11);
- }
- void lcd_putc(uint8_t x, uint8_t y, char c)
- {
- COMM_LCD = 0x80 | (y << 6) | x;
- test_bf();
- DATA_LCD = c;
- test_bf();
- }
- void lcd_charrow(uint8_t chr, int8_t y, uint8_t data) {
- COMM_LCD = 0x40 | (chr << 3) | (y + 1);
- test_bf();
- DATA_LCD = data;
- test_bf();
- }
- void led_set(uint8_t pos, uint8_t status) {
- if (!status) {
- PORTB |= 1 << pos;
- } else {
- PORTB &= ~(1 << pos);
- }
- }
- char to_hex(int v) {
- v = v & 0xF;
- if (v < 0xA) {
- return v + '0';
- } else {
- return v + 'A' - 10;
- }
- }
- int main(void)
- {
- DDRD = 0x00;
- PORTD = 0xFF;
- DDRB = 0xFF;
- PORTB = 0xFF;
- ADMUX = 0x42;
- ADCSRA = 0xE7;
- extram_init();
- lcd_init();
- for (uint8_t i = 0; i < 16; i++) {
- lcd_putc(i, 0, ' ');
- lcd_putc(i, 1, ' ');
- }
- const char* const str = "POMIAR=X.DV";
- for (size_t i = 0u; i < strlen(str); ++i)
- lcd_putc(i, 0, str[i]);
- uint8_t adcl = ADCL;
- uint16_t adc = ((ADCH & 0x03) << 8) | adcl;
- uint16_t vin = (adc * 50) / 1023;
- uint16_t hi = (vin / 10) % 10;
- uint16_t lo = vin % 10;
- lcd_putc(7, 0, to_hex(hi));
- lcd_putc(9, 0, to_hex(lo));
- while(1) {
- if(PIND == 0b11111110){
- uint8_t adcl = ADCL;
- uint16_t adc = ((ADCH & 0x03) << 8) | adcl;
- uint16_t vin = (adc * 50) / 1023;
- uint16_t hi = (vin / 10) % 10;
- uint16_t lo = vin % 10;
- lcd_putc(7, 0, to_hex(hi));
- lcd_putc(9, 0, to_hex(lo));
- }
- //_delay_ms(25);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement