void initLCDSPI()
{

    volatile unsigned char temp = 0;
    // enable output compare channel 0
    TIOS |= 0x01;
    TSCR1 = 0x90; // enable timer and allow fast flag clear
    TCTL2 &= ~0x03; // Select do nothing as output compare action for channel 0
    
    // Wait 100 mS for LCD to initialize display controller
    waitus(100000);
    
    

    SPICR1 = 0x5E; // 0(SPIE) 1(SPE) 0(SPTIE) 1(MSTR) 1(CPOL) 1(CPHA) 1(SSOE) 0(LSBFE)
    SPICR2 = 0x12; // N(N/A) N(N/A) N(N/A) 1(MODFEN) 0(BIDIROE) N(N/A) 1(SPISWAI) 0(SPC0)

    SPIBR = 0x57; // baud rate is close to 12 KHz; could have been set higher for LCD
    // Tried 75kHz and LCD seems to miss one character every few(~6-8) characters at that baud rate
    
     
    waitus(3);
    clearScreen();
    turnBlinkingCursorOn();
    //printFirmwareVersion();
}
Esempio n. 2
0
/*!
 * Uebertraegt ein Kommando an das Display
 * @param cmd Das Kommando
 */
void display_cmd(BK_U8B cmd)
{
   /* Kommando cmd an das Display senden */
   shift_data_out(cmd, SHIFT_LATCH, SHIFT_REGISTER_DISPLAY);
   /* 47 us warten */
   waitus(47);
   DISPLAY_PORT = DPC;     // Alles zurueck setzen ==> Fallende Flanke von Enable

   if (cmd == DISPLAY_CLEAR)
   {
      /* 1.52 ms warten */
      waitus(1520);
   }
}
// Move cursor position right 1 space, whether the cursor is turned on or not
void cursorRightOne()
{
    char2LCD(0xFE);
    char2LCD(0x4A);
    // 100 micro second execution time
    waitus(101);   
}
// clear LCD and move cursor to line 1 column 1
void clearScreen()
{
    char2LCD(0xFE);
    char2LCD(0x51);
    // 1.5 ms execution time
    waitus(2000);
}
// move cursor to line 1 column 1
void cursorHome()
{
    char2LCD(0xFE);
    char2LCD(0x46);
    // 1.5 ms execution time
    waitus(1700);
}
void printFirmwareVersion()
{
    char2LCD(0xFE);
    char2LCD(0x70);
    // 4 ms execution time
    waitus(4500);
}
// Move cursor back one space, delete last character
void backspace() 
{
    char2LCD(0xFE);
    char2LCD(0x4E);
    // 100 us execution time
    waitus(101);    
}
Esempio n. 8
0
int
sio_read(int fd, void *buffer, word maxlen)
{
    int ret;
    ssize_t rx;

    rx = 0;    
    FD_ZERO(&ttyfds);
    FD_SET(fd, &ttyfds);
    
    waitus(5000);

    /* I'd prefer poll(2) but it is not implemented on OS X */
    ret = select(fd+1, &ttyfds, NULL, NULL, &ttytimeout);
    if(!ret) return 0;   /* Timeout */
    else if(ret == -1) { /* Error (interrupted, bad fd) */
        rigel_error("read select failed: %s\n", strerror(errno));
        return -1;
    }
    
    if(FD_ISSET(fd, &ttyfds)) {
        rx = read(fd, buffer, maxlen);
        
        //if(rx == -1) rigel_error("Cannot read from serial port! (%s)\n", strerror(errno));
    }
        
    return rx;
}
void turnUnderlineCursorOff() 
{
    char2LCD(0xFE);
    char2LCD(0x48);
    // 1.5ms micro second execution time
    waitus(1700);      
}
// turns on the LCD display. Default: LCD screen is on
void turnLCDOn()
{
    char2LCD(0xFE);
    char2LCD(0x41);
    // 100 micro second execution time
    waitus(101);
}
void turnBlinkingCursorOff() 
{
    char2LCD(0xFE);
    char2LCD(0x4C);
    // 100 micro second execution time
    waitus(101);      
}
void main(void) {
  int i;
  unsigned char buf[80];   
  unsigned char str[5];
  unsigned char first;
  unsigned char second;
  str[0]='0';
  str[1]='x';
  
  MCU_init_24MHz();
  initLCDSPI();
  // To display normal text, just enter its ASCII number. A number from 0x00 to 0x07 displays the user defined
  // custom character, 0x20 to 0x7F displays the standard set of characters, 0xA0 to 0xFD display characters and
  // symbols that are factory-masked on the ST7066U controller. 0xFE is reserved.
  // Refer to manual for full character table

  str2LCD("Voltage:"); 
      
  // Have to manually move cursor after 16 characters
  // It will eventually move to second line, but it has to go through cursor positions 0x10-0x3F from my understanding
  setCursor(0x40);  // line 2
  
  
  ATD_init();
  ATDCTL5 = 0x23; // start an A/D conversion, scan, single channel (7)
  
  while(1) {
   for(i=0; i<80; i+=8) {
    while(!(ATDSTAT0 & 0x80)); // wait until conversion is complete	
    	//ATDCTL5 = 0x07; // start the next A/D conversion (NO NEED in scan mode)
    	buf[i]   = ATDDR0H; // ignore ATDDR0L since the conversion is 8-bit only
    	buf[i+1] = ATDDR1H;
    	buf[i+2] = ATDDR2H;
    	buf[i+3] = ATDDR3H;           
    	buf[i+4] = ATDDR4H;
    	buf[i+5] = ATDDR5H;
    	buf[i+6] = ATDDR6H;
    	buf[i+7] = ATDDR7H;
    } 
    first=buf[0]>>4;
    second=buf[0]&0x0F;
    
    if (first > 0x09) {
      str[2]=first+'A'-10;
    } else {
      str[2]=first+'0';
    }
    if (second > 0x09) {
      str[3]=second+'A'-10;
    } else {
      str[3]=second+'0';
    }
    str[4]='\0';
    clearScreen();
    str2LCD("Voltage:");
    setCursor(0x40);  // line 2
    str2LCD(str);
    waitus(500000);
  } // set up a breakpoint here to observe buf[] values
}   
// Put cursor at location position
// Values 0x00-0x0F for row 1, 0x40-0x4F for row 2
void setCursor(unsigned char position) 
{
    char2LCD(0xFE);
    char2LCD(0x45);
    char2LCD(position);
    // 100 us execution time
    waitus(110);  
}
Esempio n. 14
0
/*!
 * Schreibt ein Zeichen auf das Display
 * @param data Das Zeichen
 */
void display_data(const char data)
{
   /* Zeichen aus data in den Displayspeicher schreiben */
   shift_data_out((BK_U8B) data, SHIFT_LATCH, SHIFT_REGISTER_DISPLAY | DISPLAY_RS);

   /* 47 us warten */
   waitus(47);
   DISPLAY_PORT = DPC;     // Alles zurueck setzen ==> Fallende Flanke von Enable
}
Esempio n. 15
0
void ResetDOG(void)
{
  SetBit(DOGCSPORT,  DOGCS);
  SetBit(DOGSCLPORT, DOGSCL);
  SetBit(DOGSIPORT,  DOGSI);
  SetBit(DOGA0PORT,  DOGA0);

  ClrBit(DOGRESPORT,  DOGRES);
  waitus(5);
  SetBit(DOGRESPORT,  DOGRES);
}
// Set the display contrast, value between 1 and 50. Default: 40
void setContrast(unsigned char value) 
{
    if(value < 1 || value > 50) 
    {
        return;  
    }    
    char2LCD(0xFE);
    char2LCD(0x52);
    char2LCD(value);
    // 500 us execution time
    waitus(510);       
}
// set the backlight brightness level, value between 1 and 8. Default: 8
void setBacklightBrightness(unsigned char value) 
{
    if(value < 1 || value > 8) 
    {
        return;  
    }

    char2LCD(0xFE);
    char2LCD(0x53);
    char2LCD(value);
    // 100 us execution time
    waitus(110);       
}
Esempio n. 18
0
int main (void)
{
	// init
	lcam_initport();
	lcam_reset();
	lcam_setup();

	waitms(20);

	// global vars
	unsigned char buffer[102];
	unsigned char pic_pos = 0;

	unsigned char led_val = 1;

	while(1)
	{
		digitalWrite(C,2,led_val);
		// start acquiring image
		lcam_startintegration();

		waitus(INTEGRATION);
		// end integration
		lcam_stop(buffer);

		// delay between two successive acquisitions
		waitms(DELAY);

		pic_pos = lcam_getpic(buffer);

		// begin frame
		uartSendString("START");
		//uartSendByte(pic_pos);

		
		unsigned char i = 0;
		for(i=0;i<102;i++)
		{
			uartSendByte((buffer[i]>>3)+'0');
			//waitus(100);
		}

		uartSendByte('\0');
	

		led_val ^= 1;
	}

	// never reached

}
Esempio n. 19
0
/*!
 * wartet 100 us
 */
static void mouse_sens_wait(void) {
	waitus(100);
}