Jump to content
43oh

character to LCD and buttons events


Recommended Posts

Hello,

I'm trying to make a digital clock. Using the MCU MSP430G2553, but I'm having trouble displaying the characters on the LCD. 
 
created a variable as follows: 
unsigned int sec = 00; 
I liked that the LCD aparececem both 0, but only shows one.
 
Another problem is I have 3 switch buttons, one for setup, one for increment and decrement to another, how can I add events to each of the buttons? Initially I set the 3 buttons:
#include <msp430g2553.h>
#include "lcdLib.h"
#define 	SETUP_SWITCH	BIT3;
#define 	BUTTON_UP	BIT6;
#define         BUTTON_DOWN	BIT7;

//initial value of the increment button setup
unsigned int butSetup = 0;

void main(void){
	WDTCTL = WDTPW + WDTHOLD;
 P1DIR &= ~SETUP_SWITCH;
 P1OUT |= SETUP_SWITCH;
 P1REN |= SETUP_SWITCH;
 P1IES |= SETUP_SWITCH;
 P1IFG &= ~SETUP_SWITCH;
 P1IE |= SETUP_SWITCH;

/*other buttons
... 
*/

 __delay_cycles(1000000);

 __enable_interrupt();



lcdInit(); 
lcdSetText("ECG HOLTER",3, 0);
lcdSetText("START:",4, 1);



for(i=9; i>=0 ;i--){

	lcdSetInt(i,11, 1);
	delay_ms(1000);
	if(i==0){
	lcdClear();
	registoData();
}

while(1)
{

  _bis_SR_register(LPM0_bits);
}

}

Now how can I select option for the buttons?

I am thinking about creating a switch case for each of bottoes for example, for each of the data in SWITCH_BUTTON clicks, count the number of clicks data and assign each a switch case.

for example:

switch(butSetup){
case 1:
//code ....
break;
 
case 2:
//code
break;

default:
}

Can anyone help me?

 

 

Link to post
Share on other sites

An unsigned holds a number--well, a representation of one, anyway. It is when you convert the numeric value to printable that you need to concern yourself with two digits.

 

 

Most print tools do not include leading zeroes by default. You can do this a number of ways, but you will need to do it.

 

One way is to test before output and put the leading zero yourself (if i<10).

 

Another is write your own int to chars tool (my usual method... special tools can be more efficient than general ones much of the time)

 

Another is use a tool that allows you to specify a format with the leading zeroes, such as sprintf() in C

Link to post
Share on other sites

bluehash, the hardware is a MSP430g2553 inn launch pad board, and the LCD is  HD16x02.

 

enl can you give me a example?...  for show the values in lcd i use lcdSetText(":", 13, 1) or lcdSetInt(ano, 0, 1)

void registoData(void){
	//const unsigned char table[7]={0xe,0x1b,0x11,0x11,0x11,0x11,0x1f};
/*horas e minutos*/
	unsigned int sec = 11;
	unsigned int minu = 0;
	unsigned int hora = 10;
/*dias, meses, anos*/
	unsigned int ano = 10;
	unsigned int mes = 10;
	unsigned int dia = 20;
	/*lcdSetText("Texto", Linha, Coluna);*/
	lcdSetText("YY-MM-DD", 0, 0);
	lcdSetText("HH:MM", 11, 0);

	lcdSetText("  -  -  ", 0, 1);
	lcdSetText("  -  -  ", 0, 1);
	//data
	lcdSetInt(ano, 0, 1);
	lcdSetInt(mes, 3, 1);
	lcdSetInt(dia, 6, 1);
	//hora
	//lcdSetInt(sec);
	lcdSetInt(hora, 11, 1);
	lcdSetInt(minu, 14, 1);
	while(1){
	lcdSetText(":", 13, 1);
	delay_ms(1000);
	lcdSetText(" ", 13, 1);
	delay_ms(500);
	}
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...