e3 RGB-lit LCD switches / 60000 Baud clock

I have some SA6432 switches from http://www.e3-keys.com, and awaiting for parts to convieniently hook them up. I'm looking forward to see them working, but they're faily complicated to use. For me at least. I'm posting my first real attempt to a sketch, so have some mercy on the newby?... Is anyone using the SA series switches?

The SA-'s need a clock signal while recieving data with a minimum rate of 60000. How do I make this?

The biggest to-do-job: graffics and fonts need to be sent in a specific size bitmap format. It would be such a relief if someone would post some fonts here... I'll get back here with the specific required specifications.

/* Color set for e3-keys' SA-series of RGB-lit LCD switches. (electri-fire fecit 2008)  UNFINISHED!!!
 This sketch is set up for SA6432. Datasheets and application notes at http://www.e3-keys.com 

 */

int DataPin = 0;
int ClockPin = 1;   // to do: make 60000 Baud clock for SA6432 for synchronisation

void setup ( )
{
  Serial.begin (60000) ; // required Minimum speed is 60000,  Maximum speed 2 MBaud
}

void loop ()
// The function for sending color data to SA6432
{
  int color = (00000000); 

  /* Stores color setting for Red, Green and Blue. 
   Two bits set intensity for each color, in this format: 00RRGGBB (order may have to be reversed)
   
   00 = off 01 = low 10 = medium 11 = high
   example:  00111000 . meaning:   Red: high intensity, Green medium intensity, Blue off. This would yield Orange.
   */
  int colorPrevious = (00000000); // here to check if there's been a change

  if (color != colorPrevious);   // Hey, a change. So now send the new color
  {
    Serial.print( 0x41);    // send "color command" to SA6432
    Serial.print (color, BIN);
    Serial.print  (0x43); // send "end transmission command" to SA6432
    color = colorPrevious  ; // All done! Ready for new color changes. The color that was set is retained at SA6432.
    delay (50); // determines refresh rate for color set 
  }
  { // Demo function to change "color" to be sent 

    int analogPin = 2;    // select the input pin for the potentiometer
    byte analogValue = (00000000);       // variable to store the value coming from the sensor
    analogValue = analogRead (analogPin); 
    color = analogValue/4;    // range converter: color has values 0-63 (6 bits) ,  analogValue has 0-255 .

  }
}

Did you get anywhere with this project? I have the same button/display and I'm just getting started with it.

The SA-'s need a clock signal while recieving data with a minimum rate of 60000.

This sounds like a synchronous serial interface. The code using "Serial.begin(60000);" will send asynchronous data without a clock signal. Perhaps the AVR's SPI port could be used instead?

New here. I'm not using an Arduino, but AVRs themselves. The Atmega644P/324P. I've got a ScreenKey brand LCD button working. It uses a 10 or 11 bit protocol and requires a constant 50kHz clock. I'm going to try using the SA6432/SB6432, it uses an 8-bit protocol (SPI does the job). Of course I don't have the switch to play with yet, but soon. I'm going to try to adapt the ScreenKey AVR code to the SB6432 using SPI instead of the bit banging approach. Have you had any luck with the SB6432? Thanks.

I'm sorry, I put the project on ice. I had a programmer friend with an arduino when I got these, but he got a job, thus no time, and I couldn't sustain the interest to pursue this on my own. I'm doing other stuff now, but please post your progress, and I might chip in again later.

Ok so I have a screenkey, found the sparkfun code, modified it to run on the arduino. Heres the thing, I might of modified to make it work doesnt mean I understand a single part of it.

Im fumbling through here which Im ok with, I can figure most things out given enough time - but… not being able to read this AVR code doesnt help at all.

All I want to know is - where the hell is the part that talks about the button and its pin assignment? The original code say PB7 which according to the ardiuno/pin assignment is a crystal. Still dont get where that part is.

If someone could point out the bit of code relating to that pin assignment then I could figure out how it uses the PB1/dig pin9 and PB0/dig pin8. Or if there is a dummies dummy guide to AVR atleast Id take that

#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] (somewhere?)
//       PB1 - Data (digital pin 9)
//       PB0 - Clock (digital pin 8)

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_GREEN 0x44
#define BR_RED       0x22
#define BR_BLUE  0x11
#define DK_GREEN 0x04
#define DK_RED   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(BR_GREEN);
      screenkey_write_img(start_img);
}

void show_stop()
{
      screenkey_set_color(BR_RED);
      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;
      show_start();

      while (1)
      {
            /* Button Debounce */
            uint8_t btn = PINB & 0x80;
            if (!btn)
            {
                  if (btn_db < 0x4)
                        btn_db ++;

                  if (btn_db == 0x4)
                  {
                        btn_db = 0xFF;
                        /* Button State */
                        if (state == running)
                        {
                              state = stopped;
                              show_start();
                        }
                        else if (state == stopped)
                        {
                              fcnt = 0;
                              state = running;
                              show_stop();
                        }

                  }      
            }
            else
                  btn_db = 0;

            /* Blink animation for stop display */
            if (state==running)
            {
                  if (fcnt & 0x8000)
                        if (!br_dim)
                        {
                              screenkey_set_color(DK_RED);      
                              br_dim = 1;
                        }
                  if (! (fcnt & 0x8000))
                        if (br_dim)
                        {
                              screenkey_set_color(BR_RED);
                              br_dim = 0;
                        }
            }
      }
}

void loop()
{
  
}

Also yes, I feel very dumb for not being able to figure this out myself yet.

The button is defined as PB7 at the second line below. I included the comment line above it to make it easier for you to find it in the original code.

            /* Button Debounce */
            uint8_t btn = PINB & 0x80;

You've obviously seen the comment at the top of the program that says

// This file is designed to be used on an atmega 640, running @ 16mhz,
// but should be portable to other processors

You're right, PB7 is one of the crystal pins in an Arduino with an ATmega 328. It's probably a standard I/O pin on the 640.

Hope that gets you going on the port to a 328, or whatever you have.

Aha! Thankyou hugely. Apart from the solder I just broke playing with it changing it over to PIND & 0x80 changed it to PD7 which is digital pin 7 worked fine.

I saw the line but the 0x80 didnt make sense to me as I thought well if its hex that should be 128. But seeing how it means 7 then im guessing it was 0x8... which is confusing, what type of numbering is that exactly?

I saw the line but the 0x80 didnt make sense to me as I thought well if its hex that should be 128. But seeing how it means 7 then im guessing it was 0x8... which is confusing, what type of numbering is that exactly?

It's "Hexadecimal" or "hex", take a look at the ASCII Serial Print example, in your Arduino IDE.

http://arduino.cc/en/Tutorial/ASCIITable

It's really useful for learning how hex is used, or at least how to understand em! :)

It might help you to think of 0x80 as a binary bitmap: B10000000

Assign the bits to pins on PORTB (or PORTD): 7-6-5-4-3-2-1-0

It sounds like you are in good shape now, anyway.

I think my soldering needs to be redone and I might end up converting this code to do the jobby I need (which is have the screenkey and a few other components more or less slaved to another arduino. This code looks complicated but good if I can make it dance too

http://forum.sparkfun.com/viewtopic.php?t=8312&start=30

The hex numbering thing still confuses me how it works with these pins. Id expect it to go like

0, 1, 2, 3, 4, 5, 6, 7, 8, 9 in dec is 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 in hex (well thats how i remember learning it, its been a while so i checked in case i am drunk or something)

But I found someones code that if I understand it the pin numbering goes (starting at 1) like:

0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 (making 0x80 = 7)

I'm not getting to use the coding part of my brain at work so maybe its taking a while to warm up after a long day. Perhaps on the weekend it will click for me.