[[temp_paste_page]]
 


#define IOBASE (0x3f0000)
#define MMIO(t, x) (*(unsigned t*)(IOBASE+(x)))

#define P0 MMIO(char, 0x30)
#define P2 MMIO(char, 0x32)

#define WDTCON MMIO(char, 0x07)


void clearWatchdog() {
  WDTCON = 0x0A;
}



enum lcd_command {collo = 0x0, colhi = 0x1, line = 0xB};

void lcdCommand(enum lcd_command cmd, unsigned char arg) {
  unsigned char p0 = (cmd << 4) | (arg & 0xF);
  P2 &= 0xF7;
  P2 &= 0xDF;
  P2 &= 0xFB;
  P0 = p0;
  P2 |= 0x04;
  P2 |= 0x08;
  P2 |= 0x20;
}

 void lcdData(int size, const unsigned char* data) {
  int i;
  for (i=0; i < size; i++) {
    P2 &= 0xDF;
    P2 &= 0xFB;
    P2 |= 0x04;
    P0 = data[i];
    P2 |= 0x04;
    P2 |= 0x08;
    P2 |= 0x20;
  }
}


unsigned char msg[128];


void hello() {
  // setup message
  int i=0;
#define m(v) msg[i++] = v;
  m(0xFF) m(0x10) m(0x10) m(0x10) m(0xFF) m(0);
  m(0xFF) m(0x91) m(0x91) m(0x91) m(0x81) m(0);
  m(0xFF) m(0x01) m(0x01) m(0x01) m(0x01) m(0);
  m(0xFF) m(0x01) m(0x01) m(0x01) m(0x01) m(0);
  m(0x7E) m(0x81) m(0x81) m(0x81) m(0x7E) m(0);
#undef m


  // where to print?
  lcdCommand(collo, 0);
  lcdCommand(colhi, 2);
  lcdCommand(line, 3);

  // flush data to lcd
  lcdData(5*6, msg);

}

int main() {
  int i;
  for (i = 0; i < 10000; i++)
    hello();
  
  return 0;
}

 
  temp_paste_page.txt · Last modified: 2005/01/01 09:59
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki