Exemplo n.º 1
0
void ColorLCDShield::contrast(char setting)
{
	LCDCommand(VOLCTR);      // electronic volume, this is the contrast/brightness(EPSON)
	LCDData(setting);        // volume (contrast) setting - course adjustment,  -- original was 24

	LCDCommand(NOP);         // nop(EPSON)
}
Exemplo n.º 2
0
void initLCD() {

	SysCtlPeripheralEnable(LCDPORTENABLE);
	GPIOPinTypeGPIOOutput(LCDPORT,
				0xff);

	// Please refer to the HD44780 datasheet for how these initializations work!
	SysCtlDelay((500e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, RS,  0x00 );

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3);GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x20 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	LCDCommand(0x01);	// Clear the screen.
	LCDCommand(0x06);	// Cursor moves right.
	LCDCommand(0x0f);	// Cursor blinking, turn on LCD.

	// Now change contrast, by using PWM output on GPIO pin V0 (required configuring timer)
	// You could also use the pwm.h functions instead?
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
	GPIOPinConfigure(GPIO_PB2_T3CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2);


	//GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2);
	//GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);

	unsigned long ulPeriod = (SysCtlClockGet() / 50000)/2;
	unsigned long dutyCycle1 = (unsigned long)(ulPeriod-1)*0.7;

	TimerConfigure(TIMER3_BASE, (TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM));
	TimerControlLevel(TIMER3_BASE, TIMER_BOTH, 0);
	TimerLoadSet(TIMER3_BASE, TIMER_A, ulPeriod -1);
	TimerMatchSet(TIMER3_BASE, TIMER_A, dutyCycle1);
	TimerEnable(TIMER3_BASE, TIMER_A);

	LCDCommand(0x0c);
}
Exemplo n.º 3
0
void LCD_build(unsigned char location, unsigned char *ptr){
       unsigned char i;
       if(location<8){
    	   LCDCommand(0x40+(location*8));
           for(i=0;i<8;i++)
        	   LCDWrite(ptr[ i ] );
           LCDCommand(0x80);
      }

 }
Exemplo n.º 4
0
void LCDShield::contrast(char setting)
{
	if(driver)	
		LCDCommand(VOLCTR);      // electronic volume, this is the contrast/brightness(EPSON)
	else
		LCDCommand(SETCON);      // this is the contrast (PHILLIPS)
	LCDData(setting);        // volume (contrast) setting - course adjustment,  -- original was 24

	LCDCommand(NOP);         // nop(EPSON)
}
Exemplo n.º 5
0
void initLCD() {

	// -- paramra LED test
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, 0x0F);
	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3,  0x0F );

	SysCtlPeripheralEnable(LCDPORTENABLE);

	// -- paramra port A as control
	SysCtlPeripheralEnable(LCDCTRLENABLE);

	GPIOPinTypeGPIOOutput(LCDPORT,
				0xff);

	// -- paramra port A as control
	GPIOPinTypeGPIOOutput(LCDCTRL,
					0xff);

	// Please refer to the HD44780 datasheet for how these initializations work!
	SysCtlDelay((500e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDCTRL, RS,  0x00 );

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3);GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x20 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	LCDCommand(0x01);	// Clear the screen.
	LCDCommand(0x06);	// Cursor moves right.
	LCDCommand(0x0f);	// Cursor blinking, turn on LCD.


}
Exemplo n.º 6
0
void LCDShield::contrast(char setting)
{
	if (driver == EPSON)
	{
		setting &= 0x3F;	// 2 msb's not used, mask out
		LCDCommand(VOLCTR);	// electronic volume, this is the contrast/brightness(EPSON)
		LCDData(setting);	// volume (contrast) setting - course adjustment,  -- original was 24
		LCDData(3);			// TODO: Make this coarse adjustment variable, 3's a good place to stay
	}
	else if (driver == PHILIPS)
	{
		setting &= 0x7F;	// msb is not used, mask it out
		LCDCommand(SETCON);	// contrast command (PHILLIPS)
		LCDData(setting);	// volume (contrast) setting - course adjustment,  -- original was 24
	}
}
Exemplo n.º 7
0
void LCDWritePos(unsigned char inputData,unsigned char row, unsigned char col) {
	  unsigned char address_d = 0;		// address of the data in the screen.
		switch(row)
		{
		case 0: address_d = 0x80 + col;		// at zeroth row
		break;
		case 1: address_d = 0xC0 + col;		// at first row
		break;
		case 2: address_d = 0x94 + col;		// at second row
		break;
		case 3: address_d = 0xD4 + col;		// at third row
		break;
		default: address_d = 0x80 + col;	// returns to first row if invalid row number is detected
		break;
		}

	LCDCommand(address_d);
	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7, (inputData & 0xf0) );
	GPIOPinWrite(LCDPORT, RS, 0x01);
	GPIOPinWrite(LCDPORT, E, 0x02);
	SysCtlDelay((20e-6)*CLKSPEED/100);
	GPIOPinWrite(LCDPORT, E, 0x00);

	//SysCtlDelay((100e-6)*CLKSPEED/5);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7, (inputData & 0x0f) << 4 );
	GPIOPinWrite(LCDPORT, RS, 0x01);
	GPIOPinWrite(LCDPORT, E, 0x02);
	//SysCtlDelay((20e-6)*CLKSPEED/5);
	GPIOPinWrite(LCDPORT, E, 0x00);

	//SysCtlDelay((5e-3)*CLKSPEED/5);

}
Exemplo n.º 8
0
void LCDShield::setPixel(int color, unsigned char x, unsigned char y)
{
	y	=	(COL_HEIGHT - 1) - y;
	x = (ROW_LENGTH - 1) - x;

	if (driver == EPSON) // if it's an epson
	{
		LCDCommand(PASET);  // page start/end ram
		LCDData(x);
		LCDData(ENDPAGE);

		LCDCommand(CASET);  // column start/end ram
		LCDData(y);
		LCDData(ENDCOL);

		LCDCommand(RAMWR);  // write
		LCDData((color>>4)&0x00FF);
		LCDData(((color&0x0F)<<4)|(color>>8));
		LCDData(color&0x0FF);
	}
Exemplo n.º 9
0
//============================================================================
//函数名称:LCDInit
//函数返回:无
//参数说明:无
//功能概要:LCD初始化。
//============================================================================
void LCDInit()
{
    uint_32 i = 0;
    //定义数据口为输出
    for(i = 0;i < 8;i++)
    {
        gpio_init(LcdData[i], LCD_D[i], 1,0);
    }
    //定义控制口为输出
    gpio_init (LcdControl, LCDRS, 1,0);
    gpio_init (LcdControl, LCDRW, 1,0);
    gpio_init (LcdControl, LCDE, 1,0);

    //设置指令,RS,R/W = 00, 写指令代码
    gpio_set (LcdControl, LCDRS, 0);
    gpio_set (LcdControl, LCDRW, 0);

    //功能设置-
    //设置指令
    LCDCommand(0x38);       //5*7点阵模式,2行显示,8位数据总线
    LCDCommand(0x08);       //关显示,关光标显示,不闪烁
    LCDCommand(0x01);       //清屏
    for (i=0; i<40000; i++); //延时>1.6ms
    LCDCommand(0x06);
    LCDCommand(0x14);       //光标右移一个字符位,AC自动加1
    LCDCommand(0x0C);       //开显示,关光标显示,不闪烁
}
Exemplo n.º 10
0
//LCD Init and Data Functions
void LCDInit(void) {

	set_bit(DDRB,PIN_SCE);
	set_bit(DDRB,PIN_RESET);
	set_bit(DDRB,PIN_DC);
	set_bit(DDRB,PIN_SDIN);
	set_bit(DDRB,PIN_SCLK);

	set_bit(DDRF,5);

	//PRRO write to 0
	PRR0 = (0<<PRSPI);

	// Enable SPI, Master, set clock rate fck/16
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);

	//Reset the LCD to a known state
	clear_bit(PORTB, PIN_RESET);
	set_bit(PORTB, PIN_RESET);

	LCDCommand(0x21); //Tell LCD that extended commands follow
	LCDCommand(0xB1); //Set LCD Vop (Contrast): Try 0xB1(good @ 3.3V) or 0xBF if your display is too dark
	LCDCommand(0x04); //Set Temp coefficent
	LCDCommand(0x14); //LCD bias mode 1:48: Try 0x13 or 0x14

	LCDCommand(0x20); //We must send 0x20 before modifying the display control mode
	LCDCommand(0x0C); //Set display control, normal mode. 0x0D for inverse
}
Exemplo n.º 11
0
//Usage: LCDClear(black);
//Inputs: char color: 8-bit color to be sent to the screen.
//Outputs: None
//Description: This function will clear the screen with "color" by writing the
//			   color to each location in the RAM of the LCD.
void LCDClear(int color)
{
	#ifdef EPSON
		LCDCommand(PASET);
		LCDData(0);
		LCDData(131);
	
		LCDCommand(CASET);
		LCDData(0);
		LCDData(131);

		LCDCommand(RAMWR);
	#endif
	#ifdef	PHILLIPS
		LCDCommand(PASETP);
		LCDData(0);
		LCDData(131);
	
		LCDCommand(CASETP);
		LCDData(0);
		LCDData(131);

		LCDCommand(RAMWRP);
	#endif
	
	for(unsigned int i=0; i < (131*131)/2; i++)
	{
		LCDData((color>>4)&0x00FF);
		LCDData(((color&0x0F)<<4)|(color>>8));
		LCDData(color&0x0FF);  	// nop(EPSON)
	}
	
	x_offset = 0;
	y_offset = 0;
}
Exemplo n.º 12
0
//Usage: LCDSetPixel(white, 0, 0);
//Inputs: unsigned char color - desired color of the pixel
//		  unsigned char x - Page address of pixel to be colored
//		  unsigned char y - column address of pixel to be colored
//Outputs: None
//Description: Sets the starting page(row) and column (x & y) coordinates in ram,
//  		   then writes the colour to display memory.  The ending x & y are left
//  		   maxed out so one can continue sending colour data bytes to the 'open'
//  		   RAMWR command to fill further memory.  issuing any red command
//  		   finishes RAMWR.
//**NOTE** Because this function is static, it is essentially a "private" function
//         and can only be used within this file!
void LCDSetPixel(int color, unsigned char x, unsigned char y)
{	
	#ifdef EPSON
		LCDCommand(PASET);   // page start/end ram
		LCDData(x);
		LCDData(ENDPAGE);
  
		LCDCommand(CASET);   // column start/end ram
		LCDData(y);
		LCDData(ENDCOL);
  
		LCDCommand(RAMWR);    // write
		LCDData((color>>4)&0x00FF);
		LCDData(((color&0x0F)<<4)|(color>>8));
		LCDData(color&0x0FF);  	// nop(EPSON)		
		//LCDData(color);
		//LCDData(NOP);
		//LCDData(NOP);
	#endif
	#ifdef	PHILLIPS
		LCDCommand(PASETP);   // page start/end ram
		LCDData(x);
		LCDData(ENDPAGE);
  
		LCDCommand(CASETP);   // column start/end ram
		LCDData(y);
		LCDData(ENDCOL);
  
		LCDCommand(RAMWRP);    // write
		
		LCDData((unsigned char)((color>>4)&0x00FF));
		LCDData((unsigned char)(((color&0x0F)<<4)|0x00));
	#endif

}
Exemplo n.º 13
0
//============================================================================
//函数名称:LCDShow
//函数返回:无
//参数说明:需要显示的数据
//功能概要:液晶显示data中的数据。
//============================================================================
void LCDShow(uint_8 data[32])
{
    uint_8 i;
    //LCD初始化
    LCDInit();

    //显示第1行16个字符
    gpio_set (LcdControl, LCDRS, 0);
    gpio_set (LcdControl, LCDRW, 0);
    //后7位为DD RAM地址(0x00)
    LCDCommand(0x80);

    //2.2写16个数据到DD RAM
    gpio_set (LcdControl, LCDRS, 1);
    gpio_set (LcdControl, LCDRW, 0);
    //将要显示在第1行上的16个数据逐个写入DD RAM中
    for (i = 0;i < 16;i++)
    {
    	LCDCommand(data[i]);
    }

    //显示第2行16个字符
    gpio_set (LcdControl, LCDRS, 0);
    gpio_set (LcdControl, LCDRW, 0);
    //后7位为DD RAM地址(0x40)
    LCDCommand(0xC0);

    gpio_set (LcdControl, LCDRS, 1);
    gpio_set (LcdControl, LCDRW, 0);

    //将要显示在第2行上的16个数据逐个写入DD RAM中
    for (i = 16;i < 32;i++)
    {
    	LCDCommand(data[i]);
    }

}
Exemplo n.º 14
0
void LCDInitialize()
{
	/** Set data direction on all pins to output */
	LCD_DATA0_DD = 1;
	LCD_DATA1_DD = 1;
	LCD_DATA2_DD = 1;
	LCD_DATA3_DD = 1;
	LCD_RS_DD = 1;	
	LCD_E_DD = 1;

	/** Delay for LCD to power up */
	Cpu_Delay100US(160);
	
	/** Set RS LOW */
	LCD_RS_PORT = 0;
	LCD_E_PORT = 0;

	/** Set output to 0x3*/
	LCDCommand(0x3);
	
	/** 5 ms wait */
	Cpu_Delay100US(50);
	/** Set output to 0x3 again*/
	LCDCommand(0x3);
	Cpu_Delay100US(50);
	LCDCommand(0x3);
	
	Cpu_Delay100US(2);
	
	/** Write 0x2 enable 4 bit mode*/
	LCDCommand(0x2);
	Cpu_Delay100US(20);
	
	/** Set to 4 bit mode, 2 lines */
	LCDCommand(0x28);
	Cpu_Delay100US(20);
	
	LCDCommand(0x8);
	
	LCDCommand(0x01);
	Cpu_Delay100US(20);
	
	LCDCommand(0x0C);
	
}
Exemplo n.º 15
0
/*------------------------------------------------------------------------------
Function: LCDClearChars

Description:
Clears a number of chars starting from the address specified.  This function is
not meant to span rows.

Requires:
  - LCD is initialized
  - u8Address_ is the starting address where the first character will be cleared
	- u8CharactersToClear_ is the number of characters to clear and does not cause 
    the cursor to go past the available data RAM.

Promises:
  - Message to set cursor address in the LCD is queued, then message data 
    consisting of all ' ' characters is queued to the LCD to be displayed. 
*/
void LCDClearChars(u8 u8Address_, u8 u8CharactersToClear_)
{ 
  u8 u8Index; 
  static u8 au8LCDMessage[LCD_MESSAGE_OVERHEAD_SIZE + LCD_MAX_MESSAGE_SIZE] =  {LCD_CONTROL_DATA};
  
  /* Set the cursor to the correct address */
  LCDCommand(LCD_ADDRESS_CMD | u8Address_);
  
  /* Fill the message characters with ' ' */
  for(u8Index = 0; u8Index < u8CharactersToClear_; u8Index++)
  {
    au8LCDMessage[u8Index + 1] = ' ';
  }
      
  /* Queue the message */
  TWI0WriteData(LCD_ADDRESS, u8CharactersToClear_ + 1, au8LCDMessage, STOP);
      	
} /* end LCDClearChars() */
Exemplo n.º 16
0
/*------------------------------------------------------------------------------
Function: LCDMessage

Description:
Sends a text message to the LCD to be printed at the address specified.  

Requires:
  - LCD is initialized
  - u8Message_ is a pointer to a NULL-terminated C-string
	- The message to display is no more than (40 - the selected display location) 
    characters in length
  - Any characters not desired on screen that will not be overwritten need to 
    be erased first

Promises:
  - Message to set cursor address in the LCD is queued, then message data 
    is queued to the LCD to be displayed. 
*/
void LCDMessage(u8 u8Address_, u8 *u8Message_)
{ 
  u8 u8Index; 
  static u8 au8LCDMessage[LCD_MESSAGE_OVERHEAD_SIZE + LCD_MAX_MESSAGE_SIZE] = 
                           {LCD_CONTROL_DATA};
  
  /* Set the cursor to the correct address */
  LCDCommand(LCD_ADDRESS_CMD | u8Address_);
  
  /* Fill the message */
  u8Index = 1;
  while(*u8Message_ != '\0')
  {
    au8LCDMessage[u8Index++] = *u8Message_++;
  }
    
  /* Queue the message */
  TWI0WriteData(LCD_ADDRESS, u8Index, au8LCDMessage, STOP);

} /* end LCDMessage() */
Exemplo n.º 17
0
void LCDWScrollText(char* inputText,unsigned char row, unsigned char col) {
	unsigned char address_d = 0;		// address of the data in the screen.
	switch(row)
	{
	case 0: address_d = 0x80 + col;		// at zeroth row
	break;
	case 1: address_d = 0xC0 + col;		// at first row
	break;
	case 2: address_d = 0x94 + col;		// at second row
	break;
	case 3: address_d = 0xD4 + col;		// at third row
	break;
	default: address_d = 0x80 + col;	// returns to first row if invalid row number is detected
	break;
	}

	LCDCommand(address_d);

	while(*inputText)					// Place a string, letter by letter.
		LCDWrite(*inputText++);
}
Exemplo n.º 18
0
void LCDShield::clear(int color)
{
	if (driver) // if it's an Epson
	{
		LCDCommand(PASET);
		LCDData(0);
		LCDData(131);

		LCDCommand(CASET);
		LCDData(0);
		LCDData(131);

		LCDCommand(RAMWR);
	}
	else // otherwise it's a phillips
	{
		LCDCommand(PASETP);
		LCDData(0);
		LCDData(131);

		LCDCommand(CASETP);
		LCDData(0);
		LCDData(131);

		LCDCommand(RAMWRP);
	}

	for(unsigned int i=0; i < (131*131)/2; i++)
	{
		LCDData((color>>4)&0x00FF);
		LCDData(((color&0x0F)<<4)|(color>>8));
		LCDData(color&0x0FF);
	}

	x_offset = 0;
	y_offset = 0;
}
Exemplo n.º 19
0
void initLCD() {

	//SysCtlPeripheralEnable(LCDPORTENABLE);
	GPIOPinTypeGPIOOutput(LCDPORT,
				0xff);

	// Please refer to the HD44780 datasheet for how these initializations work!
	int tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 30){
	}
	//SysCtlDelay((500e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, RS,  0x00 );

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);

	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 1){
	}
	//SysCtlDelay((20e-6)*CLKSPEED/3);
	GPIOPinWrite(LCDPORT, E, 0x00);
	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 30){
	}
	//SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);
	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 1){
		}
		//SysCtlDelay((20e-6)*CLKSPEED/3);
	GPIOPinWrite(LCDPORT, E, 0x00);
	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 30){
	}
	//SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);
	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 1){
		}
		//SysCtlDelay((20e-6)*CLKSPEED/3);
	GPIOPinWrite(LCDPORT, E, 0x00);

	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 30){
	}
	//SysCtlDelay((10e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x20 );
	GPIOPinWrite(LCDPORT, E, 0x02);
	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 1){
		}
		//SysCtlDelay((20e-6)*CLKSPEED/3);
	GPIOPinWrite(LCDPORT, E, 0x00);
	tempo = Clock_getTicks();
	while (Clock_getTicks() - tempo < 30){
	}
	//SysCtlDelay((10e-3)*CLKSPEED/3);

	LCDCommand(0x01);	// Clear the screen.
	LCDCommand(0x06);	// Cursor moves right.
	LCDCommand(0x0f);	// Cursor blinking, turn on LCD.


}
Exemplo n.º 20
0
void gotoXY(int x, int y) {
	LCDCommand(0x80 | x);
	LCDCommand(0x40 | y); 
}
Exemplo n.º 21
0
int
main(void)
{
    char stringbuffer[17];
    int distance = 0;

	// Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    ROM_FPUEnable();
    ROM_FPULazyStackingEnable();

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); //This wasn't clear at all. Note to self, everything needs enabling on this chip.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, WAKEPIN);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, REEDPIN);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, V5POWER);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, V3POWER);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, SERVO);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
  //  ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
    ROM_GPIOPinWrite(GPIO_PORTE_BASE, V3POWER, 0xFF);

#ifdef EASYOPEN
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
#endif

    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    GPIOPinConfigure(GPIO_PC6_U3RX);
    GPIOPinConfigure(GPIO_PC7_U3TX);
    ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);


    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), GPSBAUD,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), GPSBAUD,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    ROM_IntEnable(INT_UART3);
    ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT);

	SysTickPeriodSet(SysCtlClockGet()/10000);
	SysTickIntRegister(&ServoDriver);
	SysTickIntEnable();
	SysTickEnable();
    ROM_IntMasterEnable();

    GPIOIntTypeSet(GPIO_PORTA_BASE, REEDPIN, GPIO_FALLING_EDGE);
    GPIOPinIntClear(GPIO_PORTA_BASE, REEDPIN);
    GPIOPinIntEnable(GPIO_PORTA_BASE, REEDPIN);
    IntEnable(INT_GPIOA);
   // while(1){}

/*    SysCtlDelay(SysCtlClockGet()/1000);//Make sure the servo is going to get a pulse soon.
    ROM_GPIOPinWrite(GPIO_PORTE_BASE, V5POWER, 0xFF); //Turn on the 5V power to LCD + servo.
    SysCtlDelay(SysCtlClockGet()/1000);//Make sure the servo is going to get a pulse soon.*/

    EEPROMInit();
	initLCD();
	LCDCommand(0x0c);

#ifdef LOOPBACKUART
	while(1){}
#endif

#ifdef FIRSTRUN //First run, sets the eeprom to have as many tries as is desired.
    EEPROMMassErase();
    EEPROMProgram(&initialNumTries,eepromAddress,sizeof(initialNumTries));
	LCDWriteText("Setup Complete. ", 0, 0);
	LCDWriteText("Reflash Firmware", 1, 0);
	while (1){} //Don't want to do anything else now.
#endif

    EEPROMRead(&numTrieslong,eepromAddress,sizeof(numTrieslong));
//    numTries=(int)numTrieslong;
//    openLock();
 //   numTrieslong=0;
    if (numTrieslong > initialNumTries-3) //Has already opened once, so just open as needed if stuck.
    {
    	openLock();
    	numTrieslong--;
		EEPROMProgram(&numTrieslong,eepromAddress,sizeof(numTrieslong)); //Decrement EEPROM counter.
    }
    else
    {
    distance = getDistance();
    if(distance==99999){ //No fix :/
		LCDWriteText("Location unknown", 0, 0);
		LCDWriteText("Take me outside ", 1, 0);
		SysCtlDelay(SysCtlClockGet()); //Waits 3 seconds.
    }

    else if (distance>NEARENOUGH) //Valid fix, too far away.
    {
    	if ((int)numTrieslong>0) //Any attempts remaining?
    	{
			usnprintf(stringbuffer,17,"Distance: %4dm  ",distance);
			LCDWriteText(stringbuffer, 0, 0);
			numTrieslong--;
//			numTries=(int)numTrieslong;
			EEPROMProgram(&numTrieslong,eepromAddress,sizeof(numTrieslong)); //Decrement EEPROM counter.
			usnprintf(stringbuffer,17,"%2d Attempts left",(int)numTrieslong);
			LCDWriteText(stringbuffer, 1, 0);
			SysCtlDelay(SysCtlClockGet()*2);
    	}
    	else
    	{
    		LCDWriteText("Oh dear...      ", 0, 0); //Not really sure what to do, hopefully this code never runs.
    		LCDWriteText("Opening anyway. ", 1, 0);
        //	numTrieslong=initialNumTries+1;
		//	EEPROMProgram(&numTrieslong,eepromAddress,sizeof(initialNumTries)); //Set to big value
			SysCtlDelay(10*SysCtlClockGet()/3);
			openLock();
    	}
    	}
    else //Found the location!
    {
    	openLock();
    	numTrieslong=initialNumTries+1;
        //numTries=(int)numTrieslong;
    	EEPROMProgram(&numTrieslong,eepromAddress,sizeof(initialNumTries)); //Lock will now open straight away.
    }
    }

 //   BLINK(RED);
	HibernateEnableExpClk(SysCtlClockGet());
	HibernateGPIORetentionEnable();											//Enables GPIO retention after wake from hibernate.
	HibernateClockSelect(HIBERNATE_CLOCK_SEL_RAW);
	HibernateWakeSet(HIBERNATE_WAKE_PIN);
	HibernateIntRegister(&HibernateInterrupt);
	HibernateIntEnable(HIBERNATE_INT_PIN_WAKE);
	//BLINK(BLUE);

	ROM_GPIOPinWrite(GPIO_PORTE_BASE, V5POWER, 0); //GPIO pins keep state on hibernate, so make sure to power everything else down.
	ROM_GPIOPinWrite(GPIO_PORTE_BASE, V3POWER, 0); //GPIO pins keep state on hibernate, so make sure to power everything else down.
    ROM_GPIOPinWrite(GPIO_PORTB_BASE, RS|E|D4|D5|D6|D7, 0xFF); //Pull all data pins to LCD high so we're not phantom powering it through ESD diodes.
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, SERVO, 0xFF); //Likewise for the servo
    SysCtlDelay(SysCtlClockGet()/6);
    HibernateRequest();// we want to be looping'n'shit.
    while(1){}	//Lalala, I'm a sleeping right now.
}
Exemplo n.º 22
0
void main(void) {
	uint8_t result;
	uint8_t timeout;

	OSCCON=0xFF;	//16 MHz
	ANSELA=0;
	ANSELC=0;
	nWPUEN=1;
	
#ifdef _1LCD	
	LCDInit();
	LCDCommand(0x01);	
#endif


#ifdef DEBUG_HILOCNT
	uint8_t	low1,low2,low3;
	uint8_t high1,high2,high3;
	uint8_t i,j;
	for (;;) {
		low1=low2=low3=0;
		high1=high2=high3=0;
		for (uint8_t i=1; i<7; i++) {
			CLRWDT();
			SetMode(i);
			if (adc1<10) low1++;
			if (adc2<10) low2++;
			if (adc3<10) low3++;
			if (adc1>245) high1++;
			if (adc2>245) high2++;
			if (adc3>245) high3++;
		}
	
		CLRWDT();
		SetLed(0);	for (j=0; j<100; j++) __delay_ms(10);
		CLRWDT();
		if (low1==0) low1=9; 
		SetLed(low1); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (low2==0) low2=9; 
		SetLed(low2); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (low3==0) low3=9; 
		SetLed(low3); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (high1==0) high1=9; 
		SetLed(high1); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (high2==0) high2=9; 
		SetLed(high2); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (high3==0) high3=9; 
		SetLed(high3); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
	}	
#endif


	// Loop here forever - or at least until  we timeout and go into
	// permanent low-power sleep that can only be awakened by a reset
	timeout=TIMEOUT;
	for (;;) {
//		VREGPM=0; 	// Fast wakeup
		CLRWDT();
		WatchDogOn();
		// Try to identify the connected transistor
		result=Measure();
		CLRWDT();

		// If no transistor is found just briefly flash the power-on LED
		if (result==RES_NONE) {
			SetLed(LED_PWR);
		} else {
			// We have identified a transisor type and pinout, so flash the
			// right LEDs and also reset the timeout
			timeout=TIMEOUT;
			if (result&RES_NPN) SetLed(LED_NPN);
			if (result&RES_PNP) SetLed(LED_PNP);
			if (result&RES_NCH) SetLed(LED_NCH);
			__delay_ms(5);
			SetLed(result&0x0f);
			if (result&RES_NCH) {
				__delay_ms(5);
				SetLed(LED_PWR);
			}	
		}
		__delay_ms(5);
		SetLed(LED_OFF);

		// Check if it's time to shut down and go into a deep sleep
		// that will only be awakened by pressing the Reset/Power button
		if (--timeout==0) Shutdown();

		// Sleep for a few hundred mS to conserve power and then wake up by the watchdog
		// and make a new measurement
		CLRWDT();
		SLEEP();
	}


}
Exemplo n.º 23
0
uint8_t Measure(void) {
	uint8_t	low1,low2,low3;
	uint8_t high1,high2,high3;
	uint8_t lows,highs;
	uint8_t result;
	uint8_t delta1,delta2;

	result=RES_NONE;
	low1=low2=low3=0;
	high1=high2=high3=0;

	for (uint8_t i=1; i<7; i++) {
		CLRWDT();
		SetMode(i);
		if (adc1<10) low1++;
		if (adc2<10) low2++;
		if (adc3<10) low3++;
		if (adc1>245) high1++;
		if (adc2>245) high2++;
		if (adc3>245) high3++;
	}
	CLRWDT();
	
	lows=low1+low2+low3;
	highs=high1+high2+high3;
	
	if ((lows==6) && (highs==6)) { // NFET Signature
		result=RES_NCH;
		// Handle this in the most simplistic way according to the measurements
		// of a 2N7000 NFET. This is probably not correct and will possibly not work
		// in all cases.
		if (low1==1) {
			if (low2==2) result+=RES_GDS;
			if (low2==3) result+=RES_DGS;
		}
		if (low1==2) {
			if (low2==1) result+=RES_SDG;
			if (low2==3) result+=RES_SGD;
		}
		if (low1==3) {
			if (low2==1) result+=RES_DSG;
			if (low2==2) result+=RES_GSD;
		}
	}	

	if ((lows==5) && (highs==4)) { // NPN Signature
		result=RES_NPN;
		if (low1==3) {
			delta1=SetAll(ILH, HII); 	// Test BEC
			delta2=SetAll(IHL, HII);	// Test BCE
			if (delta1<delta2) {
				result+=RES_BEC;
			} else {
				result+=RES_BCE;
			}
		}
		if (low2==3) {
			delta1=SetAll(LIH, IHI);	// Test EBC
			delta2=SetAll(HIL, IHI);	// Test CBE
			if (delta1<delta2) {
				result+=RES_EBC;
			} else {
				result+=RES_CBE;
			}
		}
		if (low3==3) {
			delta1=SetAll(LHI, IIH);	// Test ECB
			delta2=SetAll(HLI, IIH);	// Test CEB
			if (delta1<delta2) {
				result+=RES_ECB;
			} else {
				result+=RES_CEB;
			}
		}
		
	}

	//MPSA92 PNP  1=E 2=B 3=C
	if ((lows==4) && (highs==5)) { // PNP Signature
		result=RES_PNP;
		if (high1==3) {
			delta1=SetAll(ILH, LII); 	// Test BEC
			delta2=SetAll(IHL, LII);	// Test BCE
			if (delta1>delta2) {
				result+=RES_BEC;
			} else {
				result+=RES_BCE;
			}
		}
		if (high2==3) {
			delta1=SetAll(LIH, ILI);	// Test EBC
			delta2=SetAll(HIL, ILI);	// Test CBE
			if (delta1>delta2) {
				result+=RES_EBC;
			} else {
				result+=RES_CBE;
			}
		}
		if (high3==3) {
			delta1=SetAll(LHI, IIL);	// Test ECB
			delta2=SetAll(HLI, IIL);	// Test CEB
			if (delta1>delta2) {
				result+=RES_ECB;
			} else {
				result+=RES_CEB;
			}
		}
	}


#ifdef _1LCD 
	LCDCommand(0x01);	// Clear
	if (result>=100 && result<=199) {
		LCDData('N');
		LCDData('P');
		LCDHexAt(delta1,3);
		LCDHexAt(delta2,6);
		LCDCommand(0xD0);
		LCDHexAt(0xB0+base,8);
		LCDHexAt(0xE0+emitter,11);
		LCDHexAt(0xC0+collector,14);
	}
	if (result>=200) {
		LCDData('P');
		LCDData('N');
		LCDHexAt(delta1,3);
		LCDHexAt(delta2,6);
		LCDCommand(0xD0);
		LCDHexAt(0xB0+base,8);
		LCDHexAt(0xE0+emitter,11);
		LCDHexAt(0xC0+collector,14);
	}
#endif

	return result;
}
Exemplo n.º 24
0
void LCDShield::init(int type, bool colorSwap)
{
	driver = type;
	
	// Initialize the control pins, and reset display:
	cbi(LCD_PORT_SCK, SCK_PIN);	// CLK = LOW
	cbi(LCD_PORT_DIO, DIO);		// DIO = LOW
	delayMicroseconds(10);		// 10us delay
	sbi(LCD_PORT_CS, CS);		// CS = HIGH
	delayMicroseconds(10);		// 10uS Delay
	cbi(LCD_PORT_RES, LCD_RES);	// RESET = LOW
	delay(200);					// 200ms delay
	sbi(LCD_PORT_RES, LCD_RES);	// RESET = HIGH
	delay(200);					// 200ms delay
	sbi(LCD_PORT_SCK, SCK_PIN);	// SCK_PIN = HIGH
	sbi(LCD_PORT_DIO, DIO);		// DIO = HIGH
	delayMicroseconds(10);		// 10us delay
	
	if (driver == EPSON)
	{
		LCDCommand(DISCTL);	// Display control (0xCA)
		LCDData(0x0C);		// 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default)
		LCDData(0x20);		// nlines/4 - 1 = 132/4 - 1 = 32 duty
		LCDData(0x00);		// No inversely highlighted lines
		
		LCDCommand(COMSCN);	// common scanning direction (0xBB)
		LCDData(0x01);		// 1->68, 132<-69 scan direction
		
		LCDCommand(OSCON);	// internal oscialltor ON (0xD1)
		LCDCommand(SLPOUT);	// sleep out (0x94)
		
		LCDCommand(PWRCTR);	// power ctrl (0x20)
		LCDData(0x0F);		// everything on, no external reference resistors
		
		LCDCommand(DISINV);	// invert display mode (0xA7)
		
		LCDCommand(DATCTL);	// data control (0xBC)
		LCDData(0x03);		// Inverse page address, reverse rotation column address, column scan-direction	!!! try 0x01
		LCDData(0x00);		// normal RGB arrangement
		LCDData(0x02);		// 16-bit Grayscale Type A (12-bit color)
		
		LCDCommand(VOLCTR);	// electronic volume, this is the contrast/brightness (0x81)
		LCDData(32);		// volume (contrast) setting - fine tuning, original (0-63)
		LCDData(3);			// internal resistor ratio - coarse adjustment (0-7)
		
		LCDCommand(NOP);	// nop (0x25)

		delay(100);

		LCDCommand(DISON);	// display on (0xAF)
	}
	else if (driver == PHILIPS)
	{
		LCDCommand(SLEEPOUT);	// Sleep Out (0x11)
		LCDCommand(BSTRON);   	// Booster voltage on (0x03)
		LCDCommand(DISPON);		// Display on (0x29)
		
		//LCDCommand(INVON);		// Inversion on (0x20)
		
		// 12-bit color pixel format:
		LCDCommand(COLMOD);		// Color interface format (0x3A)
		LCDData(0x03);			// 0b011 is 12-bit/pixel mode
		
		LCDCommand(MADCTL);		// Memory Access Control(PHILLIPS)
		if (colorSwap) 
			LCDData(0x08);
		else
			LCDData(0x00);
		
		LCDCommand(SETCON);		// Set Contrast(PHILLIPS)
		LCDData(0x30);
		
		LCDCommand(NOPP);		// nop(PHILLIPS)
	}
}
Exemplo n.º 25
0
void ColorLCDShield::init(int type)
{
	driver = type;

	delay(200);

	cbi(LCD_PORT_SCK, SCK);     //CLK = LOW
	cbi(LCD_PORT_DIO, DIO);     //DIO = LOW
	delayMicroseconds(10);
	sbi(LCD_PORT_CS, CS);       //CS = HIGH
	delayMicroseconds(10);
	cbi(LCD_PORT_RES, LCD_RES); //RESET = LOW
	delay(200);
	sbi(LCD_PORT_RES, LCD_RES); //RESET = HIGH
	delay(200);
	sbi(LCD_PORT_SCK, SCK);     // SCK = HIGH
	sbi(LCD_PORT_DIO, DIO);     // DIO = HIGH
	delayMicroseconds(10);

	LCDCommand(DISCTL);   // display control(EPSON)
	LCDData(0x0C);        // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default)
	LCDData(0x20);
	LCDData(0x00);
	LCDData(0x01);

	LCDCommand(COMSCN);   // common scanning direction(EPSON)
	LCDData(0x01);

	LCDCommand(OSCON);    // internal oscialltor ON(EPSON)

	LCDCommand(SLPOUT);   // sleep out(EPSON)
	LCDCommand(SLEEPOUT); //sleep out(PHILLIPS)

	LCDCommand(PWRCTR);   // power ctrl(EPSON)
	LCDData(0x0F);        //everything on, no external reference resistors
	LCDCommand(BSTRON);   //Booset On(PHILLIPS)

	LCDCommand(DISINV);   // invert display mode(EPSON)

	LCDCommand(DATCTL);   // data control(EPSON)
	LCDData(0x03);        // correct for normal sin7
	LCDData(0x00);        // normal RGB arrangement
	LCDData(0x02);        // 16-bit Grayscale Type A

	LCDCommand(COLMOD);   // Set Color Mode(PHILLIPS)
	LCDData(0x03);

	LCDCommand(MADCTL);   // Memory Access Control(PHILLIPS)
	LCDData(0xC8);


	LCDCommand(VOLCTR);   // electronic volume, this is the contrast/brightness(EPSON)
	LCDData(0x24);        // volume (contrast) setting - fine tuning, original
	LCDData(0x03);        // internal resistor ratio - coarse adjustment
	LCDCommand(SETCON);   // Set Contrast(PHILLIPS)
	LCDData(0x30);

	LCDCommand(NOP);      // nop(EPSON)
	LCDCommand(NOPP);     // nop(PHILLIPS)

	delayMicroseconds(200);

	LCDCommand(DISON);    // display on(EPSON)
	LCDCommand(DISPON);   // display on(PHILLIPS)
}
Exemplo n.º 26
0
void LCDScrollRight(){
	LCDCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
	}
Exemplo n.º 27
0
void Temperature(void){
  unsigned short ADCReceived, ADCReceived2, Res1IntShort,Res2IntShort;
  float Res1Float,Res2Float,Temp1Float,Temp2Float,ADCReceived1Float,ADCReceived2Float,Rref=2500;
  char LCDOutput[14];
  unsigned short LCDTemp1[3],LCDTemp2[3];
  unsigned char dummychar;

        
        ADCReceived=(ADC_In(0x87));//ADCReceived=(ADC_In(0x07)>>6); //  Read Analog value from AN7
        ADCReceived2=(ADC_In(0x86));//ADCReceived2=(ADC_In(0x06)>>6);//  Read Analog value from AN6
        
        ADCReceived2Float=(float) ADCReceived2;
        ADCReceived1Float=(float) ADCReceived;

        Res2Float= (ADCReceived2Float/1023/7.47*Rref);
        Res1Float= (ADCReceived1Float/1023/7.47*Rref);
        Res2IntShort=(unsigned short) Res2Float;
        Res1IntShort=(unsigned short) Res1Float;

        Temp2Float=  (Res2Float-100)/0.385;
        Temp1Float=  (Res1Float-100)/0.385;


        Temp2IntShort=(unsigned char) Temp2Float;
        Temp1IntShort=(unsigned char) Temp1Float;
        
        Temp1Global=Temp1IntShort;
        Temp2Global=Temp2IntShort;
        //SCI_OutString("Raw 1 :");SCI_OutUDec(ADCReceived);SCI_OutString(" Res1 :");SCI_OutUDec(Res1IntShort);SCI_OutString(" Temp1:");SCI_OutUDec(Temp1IntShort);SCI_OutString("  || Raw 2:");SCI_OutUDec(ADCReceived2);SCI_OutString(" Res : ");SCI_OutUDec(Res2IntShort);SCI_OutString(" Temp : ");SCI_OutUDec(Temp2IntShort);OutCRLF();
        
        LCDTemp2[0]= (Temp2IntShort/100);Temp2IntShort=Temp2IntShort-LCDTemp2[0]*100;
        LCDTemp2[1]= (Temp2IntShort/10);Temp2IntShort=Temp2IntShort-LCDTemp2[1]*10;
        LCDTemp2[2]= Temp2IntShort;
  
        LCDTemp1[0]= (Temp1IntShort/100);Temp1IntShort=Temp1IntShort-LCDTemp1[0]*100;
        LCDTemp1[1]= (Temp1IntShort/10);Temp1IntShort=Temp1IntShort-LCDTemp1[1]*10;
        LCDTemp1[2]= Temp1IntShort;
        

// Update the temperature values on the LCD
LCDCommand(0x80+0x07);//Goto first temperature address
        LCD_OutChar((LCDTemp1[0]+'0'));
        LCD_OutChar((LCDTemp1[1]+'0'));
        LCD_OutChar((LCDTemp1[2]+'0'));
              
LCDCommand(0x80+0x47); //Goto second temperature address
        LCD_OutChar((LCDTemp2[0]+'0'));
        LCD_OutChar((LCDTemp2[1]+'0'));
        LCD_OutChar((LCDTemp2[2]+'0'));

//Goto Idle Location        
        LCDCommand(0x80+0x4F);
        
//Change the character at this location so that we know the Micro is working        
        if(globalidle==1){
          LCD_OutChar(0xb0);
          globalidle=2;
        } else{
          LCD_OutChar(0x7c);
          globalidle=1;
        }
        
}
Exemplo n.º 28
0
void LCDScrollLeft(){
	LCDCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
	}
/*--------------------------------------------------------------------------------------------------------------------
Function: UserAppInitialize

Description:
Initializes the State Machine and its variables.

Requires:
  -

Promises:
  - 
*/
void UserAppInitialize(void)
{
  u8 au8WelcomeMessage[] = "REAL TIME HR GRAPH";
  u8 au8Instructions[] = "B0 toggles radio";
  
  /* Clear screen and place start messages */
#ifdef MPG1
  LCDCommand(LCD_CLEAR_CMD);
  LCDMessage(LINE1_START_ADDR, au8WelcomeMessage); 
  LCDMessage(LINE2_START_ADDR, au8Instructions); 

  /* Start with LED0 in RED state = channel is not configured */
  LedOn(RED);
#endif /* MPG1 */
  
#ifdef MPG2
  PixelAddressType sStringLocation = {LCD_SMALL_FONT_LINE0, LCD_LEFT_MOST_COLUMN}; 
  LcdClearScreen();
  LcdLoadString(au8WelcomeMessage, LCD_FONT_SMALL, &sStringLocation); 
  sStringLocation.u16PixelRowAddress = LCD_SMALL_FONT_LINE1;
  LcdLoadString(au8Instructions, LCD_FONT_SMALL, &sStringLocation); 
  
  /* Start with LED0 in RED state = channel is not configured */
  LedOn(RED0);
#endif /* MPG2 */
  
 /* Configure ANT for this application */
  G_stAntSetupData.AntChannel          = ANT_CHANNEL_USERAPP;
  G_stAntSetupData.AntSerialLo         = ANT_SERIAL_LO_USERAPP;
  G_stAntSetupData.AntSerialHi         = ANT_SERIAL_HI_USERAPP;
  G_stAntSetupData.AntDeviceType       = ANT_DEVICE_TYPE_USERAPP;
  G_stAntSetupData.AntTransmissionType = ANT_TRANSMISSION_TYPE_USERAPP;
  G_stAntSetupData.AntChannelPeriodLo  = ANT_CHANNEL_PERIOD_LO_USERAPP;
  G_stAntSetupData.AntChannelPeriodHi  = ANT_CHANNEL_PERIOD_HI_USERAPP;
  G_stAntSetupData.AntFrequency        = ANT_FREQUENCY_USERAPP;
  G_stAntSetupData.AntTxPower          = ANT_TX_POWER_USERAPP;
 
  /* If good initialization, set state to Idle */
  if( AntChannelConfig(ANT_SLAVE) )
  {
    /* Channel is configured, so change LED to yellow */
#ifdef MPG1
    LedOff(RED);
    LedOn(YELLOW);
#endif /* MPG1 */
    
#ifdef MPG2
    LedOn(GREEN0);
#endif /* MPG2 */
    
    UserApp_StateMachine = UserAppSM_Idle;
  }
  else
  {
    /* The task isn't properly initialized, so shut it down and don't run */
#ifdef MPG1
    LedBlink(RED, LED_4HZ);
#endif /* MPG1 */
    
#ifdef MPG2
    LedBlink(RED0, LED_4HZ);
#endif /* MPG2 */

    UserApp_StateMachine = UserAppSM_Error;
  }

} /* end UserAppInitialize() */
Exemplo n.º 30
0
//Usage: LCDInit();
//Inputs: None
//Outputs: None
//Description:  Initializes the LCD regardless of if the controlller is an EPSON or PHILLIPS.
void LCDInit(void)
{
	delay_ms(200);
							
	cbi(LCD_PORT, SCK);//output_low (SPI_CLK);//output_low (SPI_DO);
	cbi(LCD_PORT, DIO);
	delay_us(10);
    sbi(LCD_PORT, CS);								//output_high (LCD_CS);
    delay_us(10);
    cbi(LCD_PORT, LCD_RES);								//output_low (LCD_RESET);
    delay_ms(200);
    sbi(LCD_PORT, LCD_RES);							//output_high (LCD_RESET);
	delay_ms(200);
	sbi(LCD_PORT, SCK);
	sbi(LCD_PORT, DIO);
    delay_us(10);
	
    LCDCommand(DISCTL);  	// display control(EPSON)
    LCDData(0x0C);   		// 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default)
	LCDData(0x20);    
	//LCDData(0x02);
	LCDData(0x00);
	
	LCDData(0x01);
	
    LCDCommand(COMSCN);  	// common scanning direction(EPSON)
    LCDData(0x01);
    
    LCDCommand(OSCON);  	// internal oscialltor ON(EPSON)
	
    LCDCommand(SLPOUT);  	// sleep out(EPSON)
	LCDCommand(SLEEPOUT);	//sleep out(PHILLIPS)
    
    LCDCommand(PWRCTR); 	// power ctrl(EPSON)
    LCDData(0x0F);    		//everything on, no external reference resistors
    LCDCommand(BSTRON);		//Booset On(PHILLIPS)
	
	LCDCommand(DISINV);  	// invert display mode(EPSON)
	LCDCommand(INVON);		// invert display mode(PHILLIPS)
    
    LCDCommand(DATCTL);  	// data control(EPSON)
    LCDData(0x03);			//correct for normal sin7
	LCDData(0x00);   		// normal RGB arrangement
	//LCDData(0x01);		// 8-bit Grayscale
	LCDData(0x02);			// 16-bit Grayscale Type A
	
	LCDCommand(MADCTL);		//Memory Access Control(PHILLIPS)
	LCDData(0xC8);
	
	LCDCommand(COLMOD);		//Set Color Mode(PHILLIPS)
	LCDData(0x02);	
	
    LCDCommand(VOLCTR);  	// electronic volume, this is the contrast/brightness(EPSON)
    //LCDData(0x18);   		// volume (contrast) setting - fine tuning, original
	LCDData(0x24);   		// volume (contrast) setting - fine tuning, original
    LCDData(0x03);   		// internal resistor ratio - coarse adjustment
	LCDCommand(SETCON);		//Set Contrast(PHILLIPS)
	LCDData(0x30);	
    
    LCDCommand(NOP);  	// nop(EPSON)
	LCDCommand(NOPP);		// nop(PHILLIPS)
	
	delay_ms(200);

    LCDCommand(DISON);   	// display on(EPSON)
	LCDCommand(DISPON);	// display on(PHILLIPS)
}