implement a counter and blinking message

This commit is contained in:
MegiDervishi 2021-01-05 00:10:53 +01:00
parent d0c8ceb6ed
commit 099cfc9795
4 changed files with 92 additions and 28 deletions

View file

@ -1,21 +1,19 @@
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include "arduinolib.h"
/* Configure the pins of arduino */
void Arduinolib__dinit_step(Arduinolib__dinit_out *out){
//control
/* First configure the pins of arduino and then
Initialize the LCD as described in the datasheet using the particular delays */
void Arduinolib__lcd_init_step(Arduinolib__lcd_init_out *out){
//control pins
LCD_E_DDR |= (1 << LCD_E_PIN);
LCD_RS_DDR |= (1 << LCD_RS_PIN);
//data
//data pins
LCD_D4_DDR |= (1 << LCD_D4_PIN);
LCD_D5_DDR |= (1 << LCD_D5_PIN);
LCD_D6_DDR |= (1 << LCD_D6_PIN);
LCD_D7_DDR |= (1 << LCD_D7_PIN);
}
/* Initialize the LCD as described in the datasheet */
void Arduinolib__lcd_init_step(Arduinolib__lcd_init_out *out){
_delay_ms(50); //power delay more than 15ms
@ -66,7 +64,6 @@ void Arduinolib__lcd_init_step(Arduinolib__lcd_init_out *out){
/* send an 8bit information to the LCD register in order to be written */
void Arduinolib__lcd_write_step(uint8_t info, Arduinolib__lcd_write_out *out){
//(info & 1 << 4) ? LCD_D4_PORT |= (1 << LCD_D4_PIN) : LCD_D4_PORT &= ~(1 << LCD_D4_PIN)
if (info & 1<<4){
LCD_D4_PORT |= (1 << LCD_D4_PIN);
}
@ -101,7 +98,7 @@ void Arduinolib__lcd_write_step(uint8_t info, Arduinolib__lcd_write_out *out){
_delay_us(1);
}
/* send an 8bit instruction to the LCD instruction register */
/* send an 8bit instruction(command) to the LCD instruction register */
void Arduinolib__lcd_cmd_step(uint8_t cmd, Arduinolib__lcd_cmd_out *out){
LCD_RS_PORT &= ~(1 << LCD_RS_PIN); //low
@ -123,9 +120,49 @@ void Arduinolib__lcd_char_step(uint8_t char_data, Arduinolib__lcd_char_out *out)
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[], int line, Arduinolib__lcd_string_out *out){
/*const char* Arduinolib__int_to_string_step(uint8_t number, Arduinolib__int_to_string_out *out){
char *lstring = "mrgi";
//itoa(number, lstring, 10);
return lstring;
}*/
/* give a string to display to the LCD*/
void Arduinolib__lcd_string_step(uint8_t lstring[], int line, Arduinolib__lcd_string_out *out){
Arduinolib__lcd_cmd_out *o1;
Arduinolib__lcd_cmd_out *o2;
if (line == 1) {
Arduinolib__lcd_cmd_step(LCD_CURSOR_SET | LCD_START_LINE2, o1);
_delay_us(80); //more than
} else {
Arduinolib__lcd_cmd_step(LCD_CURSOR_SET | LCD_START_LINE1, o2);
_delay_us(80);
}
volatile int i = 0;
for (i = 0; lstring[i] != 0 ; i++) {
Arduinolib__lcd_char_out *o3;
Arduinolib__lcd_char_step(lstring[i], o3);
_delay_us(80); //more than 39us
}
}
void Arduinolib__lcd_int_step(uint8_t numb, int line, Arduinolib__lcd_int_out *out){
char lstring[80];
itoa(numb, lstring, 10);
Arduinolib__lcd_string_out *o;
Arduinolib__lcd_string_step(lstring, line, o);
}
/*void Arduinolib__lcd_string_step(uint8_t lstring[], Arduinolib__lcd_string_out *out){
volatile int i = 0;
for (i = 0; lstring[i] != 0 ; i++) {
Arduinolib__lcd_char_out *o3;
Arduinolib__lcd_char_step(lstring[i], o3);
_delay_us(80); //more than 39us
}
}*/
/*void Arduinolib__print_string_step(uint8_t lstring[], int line, Arduinolib__print_string_out *out){
Arduinolib__lcd_cmd_out *o1;
Arduinolib__lcd_cmd_out *o2;
if (line == 1) {
@ -143,3 +180,10 @@ void Arduinolib__lcd_string_step(uint8_t lstring[], int line, Arduinolib__lcd_st
}
}
void Arduinolib__print_int_step(uint8_t number, int line, Arduinolib__print_int_out *out){
char lstring[80]; //buffer
itoa(number, lstring, 10); //convert int to str
Arduinolib__lcd_string_out *o;
Arduinolib__lcd_string_step(lstring, o);
}*/

View file

@ -1,8 +1,8 @@
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:string; line: int) returns ()
fun lcd_string (lstring:string; line:int) returns ()
fun lcd_int (numb:uint8_t; line:int) returns ()

View file

@ -11,9 +11,6 @@ typedef struct byte_out {
typedef byte_out Arduinolib__bitOr_out ;
typedef struct Arduinolib__dinit {
} Arduinolib__dinit_out;
typedef struct Arduinolib__lcd_init {
} Arduinolib__lcd_init_out;
@ -26,10 +23,18 @@ typedef struct Arduinolib__lcd_cmd {
typedef struct Arduinolib__lcd_char {
} Arduinolib__lcd_char_out;
typedef struct Arduinolib__int_to_string {
const char* snumb;
} Arduinolib__int_to_string_out;
typedef struct Arduinolib__lcd_string {
} Arduinolib__lcd_string_out;
void Arduinolib__dinit_step(Arduinolib__dinit_out *o);
typedef struct Arduinolib__print_string {
} Arduinolib__print_string_out;
typedef struct Arduinolib__lcd_int {
} Arduinolib__lcd_int_out;
void Arduinolib__lcd_init_step(Arduinolib__lcd_init_out *o);
@ -39,6 +44,13 @@ 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);
/*const char* Arduinolib__int_to_string_step(uint8_t number, Arduinolib__int_to_string_out *o);*/
void Arduinolib__lcd_string_step(uint8_t lstring[], int line, Arduinolib__lcd_string_out *o);
void Arduinolib__lcd_int_step(uint8_t numb, int line, Arduinolib__lcd_int_out *o);
/*void Arduinolib__print_string_step(uint8_t lstring[], int line, Arduinolib__print_string_out *o);*/
/*void Arduinolib__print_int_step(uint8_t numb, int line, Arduinolib__print_int_out *o);*/
#endif

View file

@ -1,6 +1,6 @@
open Arduinolib
node update_lcd<<period, ledMax : int; msg : string; line: int >>() returns ()
node lcd_blink_msg (period, ledMax : int; msg : string; line: int ) returns ()
var i : int;
ledTime : int;
upt : bool;
@ -16,15 +16,23 @@ let
() = lcd_string((" ", line) when downt);
tel
node main() returns ()
var j : int;
start : bool;
node lcd_counter (period:int; line: int) returns ()
var count : int;
let
j = 0 fby (j+1);
start = j < 2;
() = dinit() when start;
() = lcd_init() when start;
() = update_lcd<<6, 4, "Hello", 0>>();
() = update_lcd<<2, 1, "Hi", 1>>();
count = 0 fby (count + 1);
() = lcd_int(count/period, line);
tel
node main() returns ()
var j : int;
start : bool;
let
j = 0 fby (j+1);
start = j < 1;
() = lcd_init() when start;
() = lcd_blink_msg ((2, 1, "hello world!", 0) when not start);
() = lcd_counter ((1, 1) when not start);
tel