fixed parallel_led/ trying to make work the lcd_hept

This commit is contained in:
MegiDervishi 2021-01-03 14:39:38 +01:00
parent c6bd6f1a1a
commit 35e74807da
12 changed files with 54 additions and 65 deletions

View file

@ -2,7 +2,7 @@ CC = avr-gcc
OBJCOPY = avr-objcopy
AVRDUDE = avrdude
CFLAGS = -Os -DF_CPU=16000000UL -mmcu=atmega328p
SERIAL = /dev/cu.usbmodem141401
SERIAL = /dev/cu.usbmodem143401
ADDR = $(shell heptc -where)/c
TARGET = lcd

View file

@ -2,7 +2,7 @@ CC = avr-gcc
OBJCOPY = avr-objcopy
AVRDUDE = avrdude
CFLAGS = -Os -DF_CPU=16000000UL -mmcu=atmega328p
SERIAL = /dev/cu.usbmodem141401
SERIAL = /dev/cu.usbmodem143401
ADDR = $(shell heptc -where)/c
TARGET = prog
LIB = arduinolib

View file

@ -1,4 +1,3 @@
//#include <math.h>
#include <avr/io.h>
#include <util/delay.h>
#include "arduinolib.h"
@ -125,29 +124,22 @@ void Arduinolib__lcd_char_step(uint8_t char_data, Arduinolib__lcd_char_out *out)
}
/* give a string to display to the LCD */
void Arduinolib__lcd_string_step(uint8_t lstring[], Arduinolib__lcd_string_out *out){
void Arduinolib__lcd_string_step(uint8_t lstring[], int line, Arduinolib__lcd_string_out *out){
//uint8_t lstring = atoi(message);
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 *o1;
Arduinolib__lcd_char_step(lstring[i], o1);
Arduinolib__lcd_char_out *o3;
Arduinolib__lcd_char_step(lstring[i], o3);
_delay_us(80); //more than 39us
}
}
/*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;
}*/

View file

@ -5,4 +5,4 @@ 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 ()
fun lcd_string (lstring:string; line: int) returns ()

View file

@ -57,11 +57,3 @@
#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 *);*/

View file

@ -39,6 +39,6 @@ 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);
void Arduinolib__lcd_string_step(uint8_t lstring[], int line, Arduinolib__lcd_string_out *o);
#endif

View file

@ -2,7 +2,6 @@
#include <util/delay.h>
#include "main.h"
//#define BLINK_DELAY_MS 4000
int main (void)
{

View file

@ -1,10 +1,26 @@
open Arduinolib
node main() returns ()
node update_lcd<<period, ledMax : int; msg : string; line: int >>() returns ()
var i : int;
let
i = 0 fby (i+1);
() = dinit();
() = lcd_init();
ledTime : int;
upt : bool;
downt : bool;
let
i = 0 fby (i+1);
ledTime = i % period;
upt = ledTime < ledMax;
downt = not upt;
() = lcd_string((msg, line) when upt);
() = lcd_string((".", line) when downt);
tel
node main() returns ()
let
() = dinit();
() = lcd_init();
() = update_lcd<<6, 4, "Hello", 0>>();
() = update_lcd<<10, 5, "Hi", 1>>();
tel

View file

@ -1,32 +1,25 @@
//#include <math.h>
#include <avr/io.h>
#include <util/delay.h>
#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<<PORTD7);
//PORTB &= ~_BV(PORTB5); //put it to low
return;
}
PORTD |= (1<<PORTD7);
//PORTB |= _BV(PORTB5);
return;
if (8 <= p && p <= 13){
int pin = p - 8;
DDRB |= (1 << pin);
PORTB |= (1 << pin);
if (v == 0) PORTB &= ~(1 << pin);
}
DDRD |= _BV(DDD5);
if (v == 0)
{
PORTD &= ~(1<<PORTD5);
//PORTB &= ~_BV(PORTB4); //put it to low
return;
else if ( 0 <= p && p <= 7){
DDRD |= (1 << p);
PORTD |= (1 << p);
if (v == 0) PORTD &= ~(1 << p);
}
else { //by default
DDRB |= (1 << 5);
PORTB |= (1 << 5);
if (v == 0) PORTB &= ~(1 << 5);
}
PORTD |= (1<<PORTD5);
//PORTB |= _BV(PORTB4);
return;
}

View file

@ -1,8 +1,6 @@
#ifndef ARDUINOLIB_H
#define ARDUINOLIB_H
//#include "Arduino.h"
//#include "WConstants.h"
/* Example of a combinatorial function */
typedef struct Arduinolib__dwrite {
} Arduinolib__dwrite_out;

View file

@ -2,8 +2,6 @@
#include <util/delay.h>
#include "main.h"
//#define BLINK_DELAY_MS 4000
int main (void)
{
Prog__main_mem mem;

View file

@ -20,5 +20,6 @@ node main() returns ()
let
() = led<<3, 1, 13>>();
() = led<<4, 2, 9>>();
() = led<<3, 1, 5>>();
tel