Beruflich Dokumente
Kultur Dokumente
Raport
Lucrare de laborator nr.2
La disciplina: Proiectarea microsistemelor
A efectuat:
A verificat:
Chisinau 2015
Fluxul de date:
Codul sursa:
#include "adc.h"
void
{
ADCInit()
DDRA = 0x00;
/* ADC init */
ADCSRA = (1 << ADEN) |(1 << ADPS1) | (1 << ADPS0); /* enable ADC cu prescalerul 8 */
ADMUX = (1 << REFS0) | (0 << ADLAR);
/* tensiunea de referinta este AVCC */
}
uint16_t ADCGetData(uint8_t ch)
{
ADMUX = (ADMUX & 0xF8) | (ch & 0b111); /* alegem canalul ADC */
ADCSRA |= (1 << ADSC);
/* incepem conversia */
while (ADCSRA & (1 << ADSC)); /* asteptam finalizarea conversiei */
return ADC;
}
#ifndef VOLTAGE_H_
#define VOLTAGE_H_
#include "adc.h"
#include <stdint.h>
#define VMAX 1023 /* 10 bits */
#define VREF 5.0 /* 5 volts */
void VoltageInit(void);
float VoltageGetValue(uint8_t ch);
#endif /* VOLTAGE_H_ */
#include "voltage.h"
void VoltageInit(void) {
}
ADCInit();
#ifndef LCD_H_
#define LCD_H_
#include
#include
#include
#include
<stdint.h>
<stdarg.h>
<avr/io.h>
<util/delay.h>
LCDInit(void);
LCDCursorOn(void);
LCDCursorOff(void);
LCDSetCursor(uint8_t pos);
LCDClear(void);
LCDPrintf(uint8_t pos, const char* msg, ...);
#include "lcd.h"
static uint8_t lcd_cursor;
static void LCDDelay(void)
{
_delay_ms(1);
}
/*
* Write a standart 8 bit value to the LCD
*/
static void LCDWrite8bit(uint8_t value, uint8_t ctrl)
{
PORTC = (value & 0xF0) | ctrl;
PORTC |= LCD_EN;
PORTC &= ~LCD_EN;
LCDDelay();
}
/*
* Write a 8 bit value to the LCD using to write commands
* each transfering 4 bits (High nibble then low nibble)
*
*/
static void LCDWrite4bit(uint8_t value, uint8_t ctrl) // CTRL -> RW/RS
{
void LCDInit(void)
{
DDRC = 0xFF;
LCDWrite8bit(0b00110000, 0x00);
/* Special case "Function Set" */
LCDWrite8bit(0b00110000, 0x00);
/* Special case "Function Set" */
LCDWrite8bit(0b00110000, 0x00);
/* Initial "Function Set to change interface */
LCDWrite8bit(0b00100000, 0x00);
/* At this point display works as 4-bit mode
* and we use two writes (2 nibbles)
*/
/* N = 1 - 2 line mode,
* F = 1 - display on */
LCDWrite4bit(0b00101100, 0x00);
/* Display ON/OFF Control
* D = 0, C = 0, B = 0
* display off, cursor off, blink off
*/
LCDWrite4bit(0b00001000, 0x00);
/* Clear display */
LCDWrite4bit(0b00000001, 0x00);
/* Entry mode set */
LCDWrite4bit(0b00000110, 0x00);
/* Display on/off control */
/* Display on, cursor off, blink off */
LCDWrite4bit(0b00001100, 0x00);
}
/*
* Turn On Cursor
*/
void LCDCursorOn(void)
{
LCDWrite4bit(0b00001110, 0x00);
}
/*
* Turn Off Cursor
*/
void LCDCursorOff(void)
{
LCDWrite4bit(0b00001100, 0x00);
}
void LCDSetCursor(uint8_t pos)
{
LCDWrite4bit(0b10000000 | (pos % LCD_SIZE) | (0x40 * (pos / LCD_SIZE)), 0x00);
}
void LCDClear(void)
{
LCDWrite4bit(0b00000001, 0x00);
lcd_cursor = 0x00;
gotoXY(0, 0);
}
void LCDPrintf(uint8_t pos, const char* msg, ...)
{
char buffer[100];
va_list args;
va_start (args, msg);
vsprintf(buffer, msg, args);
/* Set address */
uint8_t i;
uint8_t line;
i = line = 0;
line = pos / LCD_SIZE;
pos = pos % LCD_SIZE;
while (buffer[i] != '\0')
{
if (buffer[i] == '\n')
{
line++;
pos = 0;
i = i + 1;
continue;
lcd_cursor = lcd_cursor + 1;
LCDWrite4bit(c, LCD_RS);