Hi,
There was already an exchange on Screenkey connection to Arduino, but it´s already closed.
My Question is, how I can run multiple screenkeys with an Arduino?
I want to generate several DATA pins.
Sparkfun’s example code describes the connection of the DATA pin only to PB1 (pin 9).
How can I duplicate this?
Although I have already dealt with the port manipulation but
do not even manage to change the pin. Even if I put any parameters in the source code on PB2 (Pin10), it remains at pin 9.
I would be very grateful for your answers.
#include <avr/io.h>
#include <avr/interrupt.h>
#include "start.h"
#include "stop.h"
volatile uint8_t phase;
volatile uint16_t bits;
volatile uint8_t cnt;
volatile uint16_t fcnt=0;
// This file is designed to be used on an atmega 640, running @ 16mhz,
// but should be portable to other processors
// Pin assignments are:
// PB7 - Button input [button drives pin low]
// PB1 - Data
// PB0 - Clock
ISR(TIMER1_OVF_vect){
fcnt++;
TCNT1 = 65536-80;
phase = ~phase;
PORTB = (PORTB & 0XFE) | (phase?1:0 );
if (phase)
{
if (!cnt)
{
PORTB |= 0x2;
return;
}
PORTB = (PORTB & 0xFD) | ((bits & 0x1) ? 2:0);
cnt --;
bits = bits >> 1;
}
}
/* Prepares a word to be sent to the lcd */
/* Parity is 1 for odd parity, 0 for even */
void screenkey_write(uint8_t data, uint8_t parity)
{
/* Block while theres still a word being sent */
while (cnt);
/* Calculate parity */
uint8_t pb = data ^ (data >> 1) ^ (data >> 2) ^ (data >> 3) ^
(data >> 4) ^ (data >> 5) ^ (data >> 6) ^ (data >> 7)
^ parity;
/* Setup the bits to send */
bits = 0x0C00 | (data << 1) | ((pb & 0x1) << 9);
/* queue it up */
cnt = 12;
}
/* Start / Stop characters */
void screenkey_start()
{
screenkey_write(0x00, 0);
}
void screenkey_stop()
{
screenkey_write(0xAA, 0);
}
// Write a 1 byte register
void screenkey_reg_1(uint8_t reg, uint8_t val)
{
screenkey_start();
screenkey_write(reg,1);
screenkey_write(val,1);
screenkey_stop();
}
// Write a 2 byte register
void screenkey_reg_2(uint8_t reg, uint8_t val1, uint8_t val2)
{
screenkey_start();
screenkey_write(reg,1);
screenkey_write(val1,1);
screenkey_write(val2,1);
screenkey_stop();
}
// Write a 108 byte image to the screen
// Data is a pointer to 108 bytes of image data to display
void screenkey_write_img(uint8_t * data)
{
uint8_t i;
screenkey_start();
screenkey_write(0x80,1);
for (i=0; i<108; i++)
screenkey_write(data[i], 1);
screenkey_stop();
}
// Bright and dark constants for each color
#define BR_RED 0x44
#define BR_GREEN 0x22
#define BR_BLUE 0x11
#define DK_GREEN 0x04
#define DK_GREEN 0x02
#define DX_BLUE 0x01
// Call with constants above, use | to make composite colors
// aka Blueish purple: BR_BLUE | DK_RED
void screenkey_set_color(uint8_t color)
{
screenkey_reg_1(0xED, color);
}
// Application specific
void show_start()
{
screenkey_set_color(DK_GREEN);
screenkey_write_img(start_img);
}
void show_stop()
{
screenkey_set_color(BR_GREEN);
screenkey_write_img(stop_img);
}
void setup()
{
enum {
stopped,
running,
valve,
x
} state;
//
uint8_t btn_db;
//
uint8_t br_dim;
//
cnt = 0;
DDRB = 0x3;
PORTB = 0x83;
TIMSK1=0x01;
////
TCCR1A = 0x00;
TCCR1B = 0x01;
TCCR1C = 0x0;
sei();
// Setup the control registers
screenkey_reg_1(0xEE, 0x00);
screenkey_reg_2(0xEF, 0x07, 0x00);
//
state = stopped;
}
void loop(){
statitaster = digitalRead(taster);
if (statitaster == HIGH){
show_stop();
delay(6);
}
else{
show_start();
delay(6);
}
}