Hitachi SP14Q002

Материал из DekatronPC
Hitacho sp14q002.jpg

Индикатор Hitachi SP14Q002 Как оказалось не имеет фреймбуфера и требует постоянного обновления картинки на входе. Arduino-код:

#include <avr/io.h>
#include <avr/interrupt.h>

#define DOUT PORTB
#define DIN PINB
#define DDIR DDRB
#define DMASK (0x0F)

#define COUT PORTD
#define CIN PIND
#define CDIR DDRD
#define CMASK (0x3C)

#define DISP (1 << 2)
#define FRAME (1 << 3)
#define LOAD (1 << 4)
#define CP (1 << 5)


#define CP_HIGH COUT |= CP
#define CP_LOW COUT &= ~CP

#define DISP_ON COUT |= DISP
#define DISP_OFF COUT &= ~DISP

#define FRAME_HIGH COUT |= FRAME
#define FRAME_LOW COUT &= ~FRAME

#define LOAD_HIGH COUT |= LOAD
#define LOAD_LOW COUT &= ~LOAD

#define X_MAX 240
#define Y_MAX (40)

#define UART_BAUD_SELECT(baudRate, xtalCpu) ((xtalCpu) / ((baudRate)*16l) - 1)
#define UART0_BAUD_RATE 500000

void uart_init(unsigned int baudrate) {
  /* Set baud rate */
  if (baudrate & 0x8000) {
    UCSR0A = (1 << U2X0);  //Enable 2x speed
    baudrate &= ~0x8000;
  }
  UBRR0H = (unsigned char)(baudrate >> 8);
  UBRR0L = (unsigned char)baudrate;

  /* Enable USART receiver and transmitter and receive complete interrupt */
  UCSR0B = _BV(RXCIE0) | (1 << RXEN0);

/* Set frame format: asynchronous, 8data, no parity, 1stop bit */
#ifdef URSEL0
  UCSR0C = (1 << URSEL0) | (3 << UCSZ00);
#else
  UCSR0C = (3 << UCSZ00);
#endif

} /* uart_init */

void setup() {
  // put your setup code here, to run once:
  //uart_init( UART_BAUD_SELECT(UART0_BAUD_RATE,16000000));
  DDIR |= DMASK;
  DOUT &= ~DMASK;
  CDIR |= CMASK;
  COUT &= ~CMASK;
  DISP_ON;
}

void sendByte(uint8_t data, uint8_t x, uint8_t y) {
  CP_HIGH;
  DOUT &= ~DMASK;
  DOUT |= (data & 0x0f);
  CP_LOW;
  _NOP();
  if (x == 0) {
    FRAME_HIGH;
  } else {
    FRAME_LOW;
  }
  _NOP();
  //send high bits:
  CP_HIGH;
  DOUT &= ~DMASK;
  DOUT |= ((data >> 4) & 0x0f);
  CP_LOW;
}
void sendData(uint8_t (*func)(uint8_t, uint8_t)) {
  for (uint8_t x = 0; x < X_MAX; ++x) {
    for (uint8_t y = 0; y < X_MAX; ++y) {
      uint8_t data = func(x, y);
      sendByte(data, x, y);
    }
    LOAD_HIGH;
    _NOP();
    LOAD_LOW;
  }
}

uint8_t white(uint8_t x, uint8_t y) {
  return 0x00;
}

uint8_t black(uint8_t x, uint8_t y) {
  return 0xff;
}

uint8_t lines(uint8_t x, uint8_t y) {
  return (x % 2) ? 0x00 : 0xFF;
}

void loop() {
  while(1){
  sendData(black);
  sendData(white);
  sendData(lines);
  }
}