Добавил:
T0miesh
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Микропроцессорные средства и системы / lab4 / GccApplication1 / GccApplication1 / main
.cpp/*
* GccApplication1.cpp
*
* Created: 12/27/2021 5:13:37 PM
* Author : SEIDALIEV
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#define PIN_SCE PD7
#define PIN_RESET PD6
#define PIN_DC PD5
#define PIN_SDIN PD4
#define PIN_SCLK PD3
#define LCD_C 0x00
#define LCD_D 0x01
#define LCD_X 84
#define LCD_Y 48
#define PORT_PCD8544 PORTD
#define DDR_PCD8544 DDRD
void pcd8544_init(void);
void pcd8544_send(uint8_t dc, uint8_t data);
void pcd8544_clear(void);
void pcd8544_set_cursor(uint8_t x, uint8_t y);
void drawRhomb(uint8_t x, uint8_t y, uint8_t height);
#define FB_LEN 504
static uint8_t fb[FB_LEN];
uint16_t pos;
void pcd8544_display_fb() {
int i;
for(i=0;i<FB_LEN; i++)
pcd8544_send(LCD_D,fb[i]);
}
void pcd8544_clear_fb(void)
{
for(pos=0;pos<FB_LEN; pos++)
fb[pos]=0;
pos=0;
}
void pcd8544_set_point(uint8_t x, uint8_t y) {
if (x < LCD_X && y < LCD_Y)
{
uint16_t index = ((y>>3)*LCD_X)+x;
fb[index]|=(1<<(y&0x07));
}
}
int main(void)
{
pcd8544_init();
pcd8544_clear();
int xStart = 25, yStart = 25, sizeW =15;
eeprom_write_byte(1, xStart);
eeprom_write_byte(10, yStart);
eeprom_write_byte(15, sizeW);
int x = eeprom_read_byte(1);
int y = eeprom_read_byte(10);
int size = eeprom_read_byte(20);
drawRhomb(x, y, size);
pcd8544_display_fb();
}
void pcd8544_init(void)
{
// GPIO Setup
DDR_PCD8544 |= (1<<PIN_SCE) | (1<<PIN_RESET) | (1<<PIN_DC) | (1<<PIN_SDIN) | (1<<PIN_SCLK);
PORT_PCD8544&=~(1<<PIN_RESET);
PORT_PCD8544|=(1<<PIN_RESET);
pcd8544_send(LCD_C, 0x21 ); // LCD Extended Commands.
pcd8544_send(LCD_C, 0xBA ); // Set LCD Vop (Contrast).
pcd8544_send(LCD_C, 0x04 ); // Set Temp coefficent. //0x04
pcd8544_send(LCD_C, 0x14 ); // LCD bias mode 1:48. //0x13
pcd8544_send(LCD_C, 0x20 ); // LCD Basic Commands
pcd8544_send(LCD_C, 0x0C ); // LCD in normal mode.
}
void pcd8544_send(uint8_t dc, uint8_t data)
{
uint8_t i;
if (dc == LCD_D)
PORT_PCD8544 |= (1<<PIN_DC);
else
PORT_PCD8544 &= ~(1<<PIN_DC);
PORT_PCD8544&=~(1<<PIN_SCE);
for (i=0; i<8; i++)
{
PORT_PCD8544=(data & 0x80) ? PORT_PCD8544 | (1<<PIN_SDIN) : PORT_PCD8544 & ~(1<<PIN_SDIN);
data=(data<<1);
PORT_PCD8544|=(1<<PIN_SCLK);
PORT_PCD8544&=~(1<<PIN_SCLK);
}
PORT_PCD8544|=(1<<PIN_SCE);
}
void pcd8544_print_string(char *str)
{
while (*str)
{
pcd8544_send (char(*str++));
}
}
void pcd8544_clear(void)
{
int i;
for (i=0; i < LCD_X * LCD_Y / 8; i++)
{
pcd8544_send(LCD_D, 0x00);
}
}
void pcd8544_set_cursor(uint8_t x, uint8_t y) {
x=x%12; y=y%6;
pcd8544_send(LCD_C, 0x40+y);
pcd8544_send(LCD_C, 0x80+x*7);
}
void drawRhomb(uint8_t x, uint8_t y, uint8_t height) {
for (int i = 0; i < height; i++) {
pcd8544_set_point(x + i, y + i);
}
for (int i = 0; i < height; i++) {
pcd8544_set_point(x + i, y - i);
}
x += (height * 2) - 1;
for (int i = 0; i < height; i++) {
pcd8544_set_point(x - i, y - i);
}
for (int i = 0; i < height; i++) {
pcd8544_set_point(x - i, y + i);
}
}