Microprocessors embedded systems

sup peeps, first time posting sorry if my questions a little vague/redundant or in the completely wrong sub section.
I’m currently completing a microprocessors unit in a CS degree. I’ve just gunned enough for a passing thus far (52.1%) so all that’s left is the final 40% assessment which is a teensy with a nokia5110 LCD glued to it.
If anyone is keen on this stuff mind if I pop some questions here for you pros or pm, exchange emails; I’ve just started going over the endless AVR documentation now but I should have a stack of questions soon. Thanks

1 Like

Just go ahead and pop your questions down. Youll get FAR more help if you let everyone see the questions you want answered. No question is too noobish because we all started somewhere

4 Likes

Also keep in mind the forum is divided by threads, so anybody not wanting to see the questions will only have this pop up as new once (thus already), even if you end up with 30 pages of questions and answers.

Bonus round is it lets the answers you get have some layer of community review, which will help catch a few of the mistakes we make… because ain’t none of us perfect, few of us experts and even fewer have somebody editing their work to make sure the sentence structure doesn’t imply anything erroneous or that it answers the question on hand, especially because as this is a forum just for fun rather than paid support, no one person can be expected to respond quickly, but chances are SOMEBODY (probably a few of them) will.

2 Likes

hey thanks for support peeps, yeah I’ll just post another thread when necessary but I’m a lazy minimalist scrub so I’ll probably just go with around the 50% mark :stuck_out_tongue: the final assessment is so extensive (for me) and I’m not much of a tinkerer after reading the documentation on debouncing and timers :weary:… II still have weeklies (weekly quiz things) I’ll likely post questions for those.
Thanks again much appreciated :star_struck:

Serial Communication

Your LCD could use one of several serial communication schemes from most likely to least likely:

  • I2C
  • SPI
  • UART

You must configure the registers on the microprocessor for the pins to communicate in the right scheme. You must look at the datasheet for the microprocessor to do this.

Lastly, you must configure the baud rate to match on both ends. The LCD will likely have an expected baud rate.

Displaying Characters

The LCD will take ascii characters and display them in the order they are given. While char ‘a’ directly translates to ascii ‘a’, and char ‘0’ directly translates to ascii ‘0,’ digit 0 does not translate to ascii ‘0’!

You must convert your integers (made of digits) to ascii characters. Let us take the integer 4567 which is stored in a variable called n. This must be converted to ‘4’, ‘5’, ‘6’, ‘7’ or “4567”

This can be done by isolating the digits:

digit[0] = (n) / 1000;
digit[1] = (n % 1000) / 100;
digit[2] = (n % 100) / 10;
digit[3] = (n % 10) / 1;

Then converting the digits to ascii:

for (int i = 0; i < totalDigits; i++)
{
ascii[i] = digit[i] + 48; //converts digit 0 to ascii ‘0’, digit 1 to ascii ‘1’ etc.
}

If your numbers can contain a different number of digits, you must use if statements to check the size before converting and displaying.

1 Like

Shit yeah like a boss! it’s UART not too bad so far, I’ve figured as much for the casting. I’ll let you know if any issues arise basically I have to make a little dungeon crawler type game, I’ll link an example of what I’ve done in about a week or so thus far I just have ASCII TOWER (name of the game) showing as a main menu :stuck_out_tongue: via the LCD I’m still waiting on the weekly quiz stuff. Thanks mate

1 Like

If you are displaying images then you likely have quite a few pixels to work with; what is your resolution? I’m assuming that pixels are only on/off and you have no control for brightness or color.

yeah man 84x48, no brightness control, just setting bits on for foreground or off for nothing. just wondering why im getting out of bounds on an exercise with involving moving a crosshair around the screen. i’ll link the error and code in a moment… quiz section section seems to be down

ermagerd nevermind… i was checking if LCD > 0 up, LCD < 47 moving down when LCD is a constant for the exercise :expressionless:. i’ll keep you posted on the assessment, still just a menu screen :stuck_out_tongue:

I know this isn’t quite what you’re doing but thought you might find it useful seeing how to program a display when all you have is a HD44780 LCD controller wired directly to ports. 8 bit data with three control lines. It also does some basic ADC conversions from three channels.

/*
 * LCD ADC Display.c
 *
 * Created: 5/10/2017 4:33:41 PM
 * Author : xpp9545
 */ 

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

//	Declaration
void setup();
void initializeLCD(void);
void LCDLineOne(char *line1);
void LCDLineTwo(char *line2);
void writeInstruction(char instruction);
unsigned char checkBusy();
void writeData(char character);
char readADC(char channel);

#define rsHigh		PORTC |= (1<<0)
#define rsLow		PORTC &= ~(1<<0)
#define rwHigh		PORTC |= (1<<1)
#define rwLow		PORTC &= ~(1<<1)
#define eHigh		PORTC |= (1<<2)
#define eLow		PORTC &= ~(1<<2)
#define writeDDRA	DDRA  |= 0xff
#define readDDRA	DDRA  &= 0

#define adcChannel1 0b01100001
#define adcChannel2 0b01100010
#define adcChannel3 0b01100011

#define startConversion	ADCSRA |= (1<<ADSC)
#define conversionRunning	ADCSRA & (1<<ADSC)

#define busyValue	PINA & (1<<7)


int main(void)
{
	setup();
	initializeLCD();
	while(1)
	{
		char pot1 = readADC(adcChannel1);
		char pot2 = readADC(adcChannel2);
		char temp = readADC(adcChannel3);

		
		char line1[] = "P1:    P2:   ";
		char line2[] = "Temp:   ";
		
		line1[3] = pot1/100 + '0';
		line1[4] = (pot1%100)/10 + '0';
		line1[5] = (pot1%10) + '0';
		
		line1[10] = pot2/100 + '0';
		line1[11] = (pot2%100)/10 + '0';
		line1[12] = (pot2%10) + '0';
		
		line2[5] = temp/100 + '0';
		line2[6] = (temp%100)/10 + '0';
		line2[7] = (temp%10) + '0';
		
		LCDLineOne(line1);
		LCDLineTwo(line2);
	}
}

void setup()
{
	DDRE = 0x03;
	PORTE = 0x03;
	DDRD = 0xFF;
	PORTD = 0;
	DDRC = 0b00000111;
	
	// set up for the ADC mode
	ADCSRA	= 0b10000111;
	ADCSRB = 0b00000000;
	

}

char readADC(char channel)
{
	ADMUX = channel;
	startConversion;
	while(conversionRunning);
	return(ADCH);
}

void writeInstruction(char value)
{
	writeDDRA;
	_delay_ms(100);
	rsLow;
	rwLow;
	_delay_us(60);
	eHigh;
	_delay_us(360);
	PORTA = value;
	_delay_us(100);
	eLow;
	_delay_us(550);
	
}

void writeData(char character)
{
	writeDDRA;
	_delay_ms(100);
	rsHigh;
	rwLow;
	_delay_us(60);
	eHigh;
	_delay_us(100);
	PORTA = character;
	_delay_us(350);
	eLow;
	_delay_us(550);
	rsLow;
}


void initializeLCD()
{
	_delay_ms(100);
	writeInstruction(0b00110000);
	_delay_ms(5);
	writeInstruction(0b00110000);
	_delay_ms(1);
	writeInstruction(0b00110000);
	
	while(checkBusy());
	writeInstruction(0b00001111);
	while(checkBusy());
	writeInstruction(0b00000001);
	while(checkBusy());
	writeInstruction(0b00000110);
	while(checkBusy());
	writeInstruction(0b00111100);
}

unsigned char checkBusy()
{
	readDDRA;
	_delay_ms(100);
	rsLow;
	rwHigh;
	_delay_us(60);
	eHigh;
	_delay_us(450);
	unsigned char value = 0x00;
	if((busyValue) == 1)
	{
		value = 0x01;
	}
	_delay_us(10);
	eLow;
	_delay_us(20);
	rwLow;
	if(value == 0)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

void LCDLineOne(char *line1)
{
	char loop, end;

	while(checkBusy());
	writeInstruction(0b10000000);
	end = strlen(line1);
	for(loop = 0; (loop < end) && (loop < 16); loop++)
	{
		while(checkBusy());
		writeData(line1[loop]);
	}
}

void LCDLineTwo(char *line2)
{
	char loop, end;

	while(checkBusy());
	writeInstruction(0b11000000);
	
	end = strlen(line2);
	for(loop = 0; (loop < end) && (loop < 16); loop++)
	{
		while(checkBusy());
		writeData(line2[loop]);
		//_delay_ms(10);
	}
}

Video of it working for reference.

1 Like

that’s awesome man, I like the structure too much easier to read than examples for timer interrupts and some of the custom macros I’ve been given. thanks

hey peeps, sorry had to jump ship on the teensy LCD thing, got as far as control for a hero to run around and avoid a single monster but just the ground level of the tower game and that’s all i submitted (missed a database exam from sleeping in; had to make up for it). anyways, I’ll link a demo vid of what I completed here eventually and the code if anyone cares, I actually have no idea where the thing (teensy) is now tbh. cheers