From e4e2aa095eba8b40c735bb62f2edb733e40c461f Mon Sep 17 00:00:00 2001 From: MegiDervishi Date: Sun, 27 Dec 2020 12:40:42 +0100 Subject: [PATCH] code lcd in c and with heptagon --- Makefile | 2 +- arduinolib.c | 192 +++++++++++++++++++++++--------- arduinolib.epi | 8 +- arduinolib.h | 66 +++++++++++ arduinolib_types.h | 47 ++++++-- lcd_c/.DS_Store | Bin 0 -> 6148 bytes lcd_c/Makefile | 37 ++++++ lcd_c/lcd.c | 130 +++++++++++++++++++++ lcd_c/lcd_definitions.h | 68 +++++++++++ parallel_led/.DS_Store | Bin 0 -> 6148 bytes parallel_led/Makefile | 42 +++++++ parallel_led/arduinolib.c | 32 ++++++ parallel_led/arduinolib.epi | 2 + parallel_led/arduinolib.h | 1 + parallel_led/arduinolib_types.h | 11 ++ led.c => parallel_led/led.c | 0 parallel_led/main.c | 17 +++ parallel_led/main.h | 4 + parallel_led/prog.ept | 24 ++++ prog.ept | 24 +--- 20 files changed, 629 insertions(+), 78 deletions(-) create mode 100644 lcd_c/.DS_Store create mode 100644 lcd_c/Makefile create mode 100644 lcd_c/lcd.c create mode 100644 lcd_c/lcd_definitions.h create mode 100644 parallel_led/.DS_Store create mode 100644 parallel_led/Makefile create mode 100644 parallel_led/arduinolib.c create mode 100644 parallel_led/arduinolib.epi create mode 100644 parallel_led/arduinolib.h create mode 100644 parallel_led/arduinolib_types.h rename led.c => parallel_led/led.c (100%) create mode 100644 parallel_led/main.c create mode 100644 parallel_led/main.h create mode 100644 parallel_led/prog.ept diff --git a/Makefile b/Makefile index 7d5678e..b5b61fd 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC = avr-gcc OBJCOPY = avr-objcopy AVRDUDE = avrdude CFLAGS = -Os -DF_CPU=16000000UL -mmcu=atmega328p -SERIAL = /dev/cu.usbmodem143401 +SERIAL = /dev/cu.usbmodem141401 ADDR = $(shell heptc -where)/c TARGET = prog LIB = arduinolib diff --git a/arduinolib.c b/arduinolib.c index 1b2e743..586433e 100644 --- a/arduinolib.c +++ b/arduinolib.c @@ -2,60 +2,152 @@ #include #include #include "arduinolib.h" -//#include "HardwareSerial.h" - -void Arduinolib__dwrite_step(int p, int v, Arduinolib__dwrite_out *out){ - /* set pin 5 of PORTB for output. i.e port 13 */ - if (p == 13){ - DDRB |= _BV(DDB5); - if (v == 0) - { - PORTB &= ~(1<i = 0; - for(j = 0; j < 100; ++j) - self->mem[j] = 0.0; + +/* send an 8bit data character to the LCD register */ +void Arduinolib__lcd_char_step(uint8_t char_data, Arduinolib__lcd_char_out *out){ + + LCD_RS_PORT |= (1 << LCD_RS_PIN); //high + LCD_E_PORT &= ~(1 << LCD_E_PIN); //low + Arduinolib__lcd_write_out *o1; + Arduinolib__lcd_write_step(char_data, o1); // upper 4 bits + Arduinolib__lcd_write_out *o2; + Arduinolib__lcd_write_step(char_data << 4, o2); // lower 4 bits +} + +/* give a string to display to the LCD */ +void Arduinolib__lcd_string_step(uint8_t lstring[], Arduinolib__lcd_string_out *out){ + + //uint8_t lstring = atoi(message); + volatile int i = 0; + for (i = 0; lstring[i] != 0 ; i++) { + Arduinolib__lcd_char_out *o1; + Arduinolib__lcd_char_step(lstring[i], o1); + _delay_us(80); //more than 39us + } } -void Mathext__st_cos_step(float a, Mathext__st_cos_out *out, Mathext__st_cos_mem *self) -{ - out->o = self->mem[self->i]; - self->i = (self->i+1) % 100; - self->mem[self->i] = cosf(a); +/*uint8_t msg[] = "Arduino"; +uint8_t msg2[] = "Hello world"; + +int main(void) { + Arduinolib__dinit_step(); + Arduinolib__lcd_init_step(); + Arduinolib__lcd_string_step(msg); + Arduinolib__lcd_cmd_step(LCD_CURSOR_SET | LCD_START_LINE2); + _delay_us(80); // more than 39us + Arduinolib__lcd_string_step(msg2); + + while(1); + return 0; }*/ + diff --git a/arduinolib.epi b/arduinolib.epi index fc4a16f..0c0a718 100644 --- a/arduinolib.epi +++ b/arduinolib.epi @@ -1,2 +1,8 @@ -fun dwrite(p:int; v:bool) returns () +type uint8_t = int +fun dinit() returns () +fun lcd_init() returns () +fun lcd_write(info:uint8_t) returns () +fun lcd_cmd(cmd:uint8_t) returns () +fun lcd_char(char_data:uint8_t) returns () +fun lcd_string (lstring:uint8_t) returns () diff --git a/arduinolib.h b/arduinolib.h index 74ec448..0674500 100644 --- a/arduinolib.h +++ b/arduinolib.h @@ -1 +1,67 @@ #include "arduinolib_types.h" + +/* LCD with 4 bit mode for an ATMEGA32P processor + + _ LCD _ _ ATMEGA32P (arduino)_ + 1 VSS -> GND + 2 VDD -> +5V + 3 V0 -> Potentiometer + 4 RS -> PortB4 (Pin 12 arduino) + 5 RW -> GND + 6 E -> PortB3 (Pin 11 arduino) + (7 - 10) -> ... + 11 D4 -> PortD5 (Pin 5 arduino) + 12 D5 -> PortD4 (Pin 4 arduino) + 13 D6 -> PortD3 (Pin 3 arduino) + 14 D7 -> PortD2 (Pin 2 arduino) + 15 A -> +5v with resistor + 16 K -> GND + +*/ + +// LCD display size +#define LCD_START_LINE1 0x00 +#define LCD_START_LINE2 0x40 + +// LCD ports/pins/ddr +#define LCD_RS_PORT PORTB +#define LCD_RS_PIN 4 +#define LCD_RS_DDR DDRB + +#define LCD_E_PORT PORTB +#define LCD_E_PIN 3 +#define LCD_E_DDR DDRB + +#define LCD_D4_PORT PORTD +#define LCD_D4_PIN 5 +#define LCD_D4_DDR DDRD + +#define LCD_D5_PORT PORTD +#define LCD_D5_PIN 4 +#define LCD_D5_DDR DDRD + +#define LCD_D6_PORT PORTD +#define LCD_D6_PIN 3 +#define LCD_D6_DDR DDRD + +#define LCD_D7_PORT PORTD +#define LCD_D7_PIN 2 +#define LCD_D7_DDR DDRD + +//LCD instructions (see LCD-1602A datasheet) +#define LCD_CLEAR 0b00000001 +#define LCD_HOME 0b00000010 +#define LCD_ENTRY_MODE 0b00000110 +#define LCD_DISPLAY_ON 0b00001100 +#define LCD_DISPLAY_OFF 0b00001000 +#define LCD_CURSOR_SET 0b10000000 +#define LCD_FUNCTION_SET_8bit 0b00110000 +#define LCD_FUNCTION_SET_4bit 0b00101000 + +// Functions +/*void dinit(void); +void lcd_init(void); +void lcd_write(uint8_t); +void lcd_cmd(uint8_t); +void lcd_char(uint8_t); +void lcd_string(uint8_t *);*/ \ No newline at end of file diff --git a/arduinolib_types.h b/arduinolib_types.h index 0570697..ff409a4 100644 --- a/arduinolib_types.h +++ b/arduinolib_types.h @@ -1,11 +1,44 @@ #ifndef ARDUINOLIB_H #define ARDUINOLIB_H -//#include "Arduino.h" -//#include "WConstants.h" -/* Example of a combinatorial function */ -typedef struct Arduinolib__dwrite { -} Arduinolib__dwrite_out; -void Arduinolib__dwrite_step(int p, int v,Arduinolib__dwrite_out *o); +//typedef struct string { +// const char *msg +//} Arduinolib__string_out; -#endif +typedef struct byte_out { + uint8_t value ; +} byte_out ; + +typedef byte_out Arduinolib__bitOr_out ; + +typedef struct Arduinolib__dinit { +} Arduinolib__dinit_out; + +typedef struct Arduinolib__lcd_init { +} Arduinolib__lcd_init_out; + +typedef struct Arduinolib__lcd_write { +} Arduinolib__lcd_write_out; + +typedef struct Arduinolib__lcd_cmd { +} Arduinolib__lcd_cmd_out; + +typedef struct Arduinolib__lcd_char { +} Arduinolib__lcd_char_out; + +typedef struct Arduinolib__lcd_string { +} Arduinolib__lcd_string_out; + +void Arduinolib__dinit_step(Arduinolib__dinit_out *o); + +void Arduinolib__lcd_init_step(Arduinolib__lcd_init_out *o); + +void Arduinolib__lcd_write_step(uint8_t info, Arduinolib__lcd_write_out *o); + +void Arduinolib__lcd_cmd_step(uint8_t cmd, Arduinolib__lcd_cmd_out *o); + +void Arduinolib__lcd_char_step(uint8_t char_data, Arduinolib__lcd_char_out *o); + +void Arduinolib__lcd_string_step(uint8_t lstring[], Arduinolib__lcd_string_out *o); + +#endif \ No newline at end of file diff --git a/lcd_c/.DS_Store b/lcd_c/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 +#include + +/* LCD with 4 bit mode for an ATMEGA32P processor + + _ LCD _ _ ATMEGA32P (arduino)_ + 1 VSS -> GND + 2 VDD -> +5V + 3 V0 -> Potentiometer + 4 RS -> PortB4 (Pin 12 arduino) + 5 RW -> GND + 6 E -> PortB3 (Pin 11 arduino) + (7 - 10) -> ... + 11 D4 -> PortD5 (Pin 5 arduino) + 12 D5 -> PortD4 (Pin 4 arduino) + 13 D6 -> PortD3 (Pin 3 arduino) + 14 D7 -> PortD2 (Pin 2 arduino) + 15 A -> +5v with resistor + 16 K -> GND + +*/ + +// LCD display size +#define LCD_START_LINE1 0x00 +#define LCD_START_LINE2 0x40 + +// LCD ports/pins/ddr +#define LCD_RS_PORT PORTB +#define LCD_RS_PIN 4 +#define LCD_RS_DDR DDRB + +#define LCD_E_PORT PORTB +#define LCD_E_PIN 3 +#define LCD_E_DDR DDRB + +#define LCD_D4_PORT PORTD +#define LCD_D4_PIN 5 +#define LCD_D4_DDR DDRD + +#define LCD_D5_PORT PORTD +#define LCD_D5_PIN 4 +#define LCD_D5_DDR DDRD + +#define LCD_D6_PORT PORTD +#define LCD_D6_PIN 3 +#define LCD_D6_DDR DDRD + +#define LCD_D7_PORT PORTD +#define LCD_D7_PIN 2 +#define LCD_D7_DDR DDRD + +//LCD instructions (see LCD-1602A datasheet) +#define LCD_CLEAR 0b00000001 +#define LCD_HOME 0b00000010 +#define LCD_ENTRY_MODE 0b00000110 +#define LCD_DISPLAY_ON 0b00001100 +#define LCD_DISPLAY_OFF 0b00001000 +#define LCD_CURSOR_SET 0b10000000 +#define LCD_FUNCTION_SET_8bit 0b00110000 +#define LCD_FUNCTION_SET_4bit 0b00101000 + +// Functions +void dinit(void); +void lcd_init(void); +void lcd_write(uint8_t); +void lcd_cmd(uint8_t); +void lcd_char(uint8_t); +void lcd_string(uint8_t *); diff --git a/parallel_led/.DS_Store b/parallel_led/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..97842b3fabdba46d4eec1719e191dd39d616b3c3 GIT binary patch literal 6148 zcmeHKJ8r`;3?kKo$coT6Fi6bLD7#{0s@yZ0XS85ulz# z@k!7dOjAU3_})K@^di#14drM3yE3Cj0k*aUbPFK4q4} zIo~#DRDcRl0V+TRsKCt?$P(K<-TY)8NCl|Ce^ +#include +#include +#include "arduinolib.h" +//#include "HardwareSerial.h" + +void Arduinolib__dwrite_step(int p, int v, Arduinolib__dwrite_out *out){ + /* set pin 5 of PORTB for output. i.e port 13 */ + if (p == 13){ + DDRC |= _BV(DDD7); + if (v == 0) + { + PORTD &= ~(1< +#include +#include "main.h" + +//#define BLINK_DELAY_MS 4000 + +int main (void) +{ + Prog__main_mem mem; + Prog__main_reset(&mem); + while(1){ + Prog__main_out _res; + Prog__main_step(&_res, &mem); + _delay_ms(1000); +} +return 0; +} \ No newline at end of file diff --git a/parallel_led/main.h b/parallel_led/main.h new file mode 100644 index 0000000..7269ffa --- /dev/null +++ b/parallel_led/main.h @@ -0,0 +1,4 @@ +#ifndef MAIN_H +#define MAIN_H +#include "prog_c/prog.h" +#endif diff --git a/parallel_led/prog.ept b/parallel_led/prog.ept new file mode 100644 index 0000000..47175e7 --- /dev/null +++ b/parallel_led/prog.ept @@ -0,0 +1,24 @@ +open Arduinolib + +node led<>() returns () +var i : int; + ledTime : int; + upt : bool; + downt : bool; + +let + i = 0 fby (i+1); + ledTime = i % period; + upt = ledTime < ledMax; + downt = not upt; + + () = dwrite((opin, true) when upt); + () = dwrite((opin, false) when downt); +tel + +node main() returns () +let + () = led<<3, 1, 13>>(); + () = led<<4, 2, 9>>(); +tel + diff --git a/prog.ept b/prog.ept index e349a16..19088e4 100644 --- a/prog.ept +++ b/prog.ept @@ -1,24 +1,10 @@ open Arduinolib -node led<>() returns () -var i : int; - ledTime : int; - upt : bool; - downt : bool; - -let - i = 0 fby (i+1); - ledTime = i % period; - upt = ledTime < ledMax; - downt = not upt; - - () = dwrite((opin, true) when upt); - () = dwrite((opin, false) when downt); -tel - node main() returns () -let - () = led<<4, 2, 13>>(); - () = led<<3, 1, 9>>(); +var i : int; +let + i = 0 fby (i+1); + () = dinit(); + () = lcd_init(); tel