Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 23rd June 2009, 12:19 AM   #61
Default

This is what i needed it for
Code:
#include <LPC210x.h>

void GlcdPort(unsigned long Data){
    IOPIN = ((IOPIN & 0xFFFFFF00 ) | Data);
}
void DelayUs(int us) {
	for (; us>0; us--);
}

void DelayMs(int ms) {
	for (; ms>0; ms--)
		DelayUs(1000);
}
int main(void){
	unsigned char x;
	PINSEL0=0x00;
	IODIR=0xFFFFFFFF;

	while(1){
		for(x=0;x<8;x++){
			GlcdPort(0xFE);
			DelayMs(500);
		}
	
	}

}
To create a GLCD Port

Last edited by AtomSoft; 23rd June 2009 at 12:19 AM.
AtomSoft is offline  
Old 23rd June 2009, 12:25 AM   #62
Default

I would define the 0xfffff00 somewhere else (and make it intuitive) so that if you do change hardware configuration, you can just change the definition section and the code will compil and run correctly.
millwood is offline  
Old 23rd June 2009, 12:27 AM   #63
Default

heh yeah thanks for tip...

Like a :

Code:
#define GLCDPORT 0xFFFFFF00
.....
.......
void GlcdPort(unsigned long Data){
    IOPIN = ((IOPIN & GLCDPORT ) | Data);
}
AtomSoft is offline  
Old 23rd June 2009, 01:55 AM   #64
Default

hey guys another issue now lol How would i set a PIN input/output? Just one like P0.8 ?

I was thinking and got this but not sure. Want advice:
Code:
IODIR = (IODIR & (~(1<<GLCD_CS1 )));
AtomSoft is offline  
Old 23rd June 2009, 02:16 AM   #65
Default

Use the set and clear registers whenever you can. They are much 'safer'. You should only use the direct GPIO if you really need to, and it's slower if you are just doing this basic set or clear.

It depends on how the program logic is working, but either:
SET_PORTA_REGISTER = BIT8;
or SET_PORTA_REGISTER = 0x01 << 8;

If you are clearing, just change it to the clear register.

If it's single pin operations, I usually define my pins like this:
Code:
#define lcd7110_BACKLIGHT_PIN  BIT31
then make MACRO's to set and clear them.
Code:
#define LCD7110_LED_ON()       pPIOA->PIO_SODR = lcd7110_BACKLIGHT_PIN;
#define LCD7110_LED_OFF()      pPIOA->PIO_CODR = lcd7110_BACKLIGHT_PIN;
This makes it easier for me to move the code to another processor.

Otherwise your code should work as is if you can't get away with using the set and clear registers. Assuming GLCD_CS1 is a pin number.
__________________
Mark Higgins
DirtyLude is online now  
Old 23rd June 2009, 02:47 AM   #66
Default

Im trying to use a 128x64 GLCD and im dieing here lol Im trying to read the data from the port and test it....
Code:
unsigned char GLCD_Read(void){
	unsigned char tmp;
	IOSET = 1<<GLCD_E;
	DelayUs(100);
	tmp = (IOPIN & (~(GLCDPORT)));
	IOCLR = 1<<GLCD_E;
	return tmp;
}
void Wait_Not_Busy(void){
unsigned long DirTmp;
unsigned char CS1Dat;
unsigned char CS2Dat;

	DirTmp = 0xFFFFFF00;
	IODIR=DirTmp;
	
	IODIR = (IODIR & (~(1<<GLCD_CS1)));
	IODIR = (IODIR & (~(1<<GLCD_CS2)));
		
 	IOCLR = 1<<GLCD_RS;
	IOSET = 1<<GLCD_RW;

	CS1Dat = (IOPIN & (1<<GLCD_CS1));
	CS2Dat = (IOPIN & (1<<GLCD_CS2));

	if (CS1Dat==1 && CS2Dat==1){
		IOCLR = 1<<GLCD_CS1;
		while (GLCD_Read()&0x80);
		IOSET = 1<<GLCD_CS1;
		IOCLR = 1<<GLCD_CS2;
		while (GLCD_Read()&0x80);
		IOSET = 1<<GLCD_CS2;
	}
	else{
		while (GLCD_Read()&0x80);
	}

	IODIR=0xFFFFFFFF;


}
EDIT
I just notice you can read a PIN without setting it to INPUT so i scapped the IODIR parts....
Code:
unsigned char GLCD_Read(void){
	unsigned char tmp;
	IOSET = 1<<GLCD_E;
	DelayUs(100);
	tmp = (IOPIN & (~GLCDPORT));
	IOCLR = 1<<GLCD_E;
	return tmp;
}
void Wait_Not_Busy(void){
//unsigned long DirTmp;
unsigned char CS1Dat;
unsigned char CS2Dat;

	//DirTmp = 0xFFFFFF00;
	//IODIR=DirTmp;
	
	//IODIR = (IODIR & (~(1<<GLCD_CS1)));
	//IODIR = (IODIR & (~(1<<GLCD_CS2)));
		
 	IOCLR = 1<<GLCD_RS;
	IOSET = 1<<GLCD_RW;

	CS1Dat = (IOPIN & (1<<GLCD_CS1));
	CS2Dat = (IOPIN & (1<<GLCD_CS2));

	if (CS1Dat==1){
		if (CS2Dat==1){
			IOCLR = 1<<GLCD_CS1;
			while (GLCD_Read()&0x80);
			IOSET = 1<<GLCD_CS1;
			IOCLR = 1<<GLCD_CS2;
			while (GLCD_Read()&0x80);
			IOSET = 1<<GLCD_CS2;
		}
	}
	else{
		while (GLCD_Read()&0x80);
	}

	//IODIR=0xFFFFFFFF;


}
My issue is in ISIS i get errors and nothing on screen....
"Command Write attempted during reset. Write Operation Failed."

Last edited by AtomSoft; 23rd June 2009 at 03:01 AM.
AtomSoft is offline  
Old 23rd June 2009, 03:04 AM   #67
Default

I'm not reading your code that closely, but if it's like the SAM7, I see two problems here. One is that the read register is totally different from the GPIO setting register. On the SAM7 it's called the Pin Data Status Register. You might want to look for the equivelant on the LPC. Also, if it's the same, the peripheral clock needs to be enabled in order to use inputs at all.
__________________
Mark Higgins
DirtyLude is online now  
Old 23rd June 2009, 03:07 AM   #68
Default

I think its just that one ... image below is more informational...

Attached Thumbnails
ARM Cortex-pin.jpg  
AtomSoft is offline  
Old 23rd June 2009, 03:18 AM   #69
Default

Ya, mine definitely works differently. I have an Output Data Status Register with what I'm currently telling it to output for the output lines, and a Pin Data Status Register with the input values.

I can see, I screwed up with one of your previous questions as well. Looks like you were asking about changing the data direction of a pin. I thought you meant setting the output on/off.

I'll drop out.
__________________
Mark Higgins
DirtyLude is online now  
Old 23rd June 2009, 03:22 AM   #70
Default

na stay in lol input is always good. You might learn and teach me some stuff

Im going to try some stuff with a simple button and test input/output strategies

Last edited by AtomSoft; 23rd June 2009 at 03:22 AM.
AtomSoft is offline  
Old 23rd June 2009, 03:45 AM   #71
Default

Ok i think i got it now lol i tried it on button and works nicely... First i was using char instead of long for a pin so causing a overflow type thing....

also i made a function to read a single pin... works nice i think...
Code:
unsigned char GLCD_Read(void){
	unsigned long tmp;
	IOSET = 1<<GLCD_E;
	DelayUs(100);
	tmp = (IOPIN & (~GLCDPORT));
	IOCLR = 1<<GLCD_E;
	return tmp;
}
unsigned char GetPin(unsigned long tPin){
	unsigned long tmp;
	DelayMs(1);
	tmp = (IOPIN & (1<<tPin));
	if(tmp == 0)
		return 0;
	else
		return 1;
}

Last edited by AtomSoft; 23rd June 2009 at 03:45 AM.
AtomSoft is offline  
Old 23rd June 2009, 10:31 AM   #72
Default

Quote:
Originally Posted by DirtyLude View Post
Ya, mine definitely works differently. I have an Output Data Status Register with what I'm currently telling it to output for the output lines, and a Pin Data Status Register with the input values.
that's chip specific, I think.
millwood is offline  
Old 23rd June 2009, 12:09 PM   #73
Default

this sucks lol trying to clear the screen and this is what i get:


This is my full code so far:
Code:
#include <LPC210x.h>

#define GLCDPORT 0xFFFFFF00
#define GLCD_RS  8
#define GLCD_E   9
#define GLCD_RW  10
#define GLCD_DI  11
#define GLCD_CS1 12
#define GLCD_CS2 13

void initGLCD(void);
void GlcdPort(unsigned long Data);
void GLCD_Write_Cmd(unsigned char data);
void ClearScreen(char normal);
void GLCD_Write_Cmd(unsigned char data);
void GLCD_Write_Data (unsigned char data);
void Wait_Not_Busy(void);
unsigned char GLCD_Read(void);
void ClrPin(unsigned long tPin);
void SetPin(unsigned long tPin);

void GlcdPort(unsigned long Data){
    IOPIN = ((IOPIN & GLCDPORT ) | Data);
}
void DelayUs(int us) {
	for (; us>0; us--);
}

void DelayMs(int ms) {
	for (; ms>0; ms--)
		DelayUs(1000);
}

void GLCD_Write_Cmd(unsigned char data){
	Wait_Not_Busy();

	ClrPin(GLCD_DI);
	ClrPin(GLCD_RW);

	GlcdPort(data);

	SetPin(GLCD_E);
	DelayUs(100);
	ClrPin(GLCD_E);
}
void GLCD_Write_Data (unsigned char data){
	Wait_Not_Busy();

	GlcdPort(data);

	SetPin(GLCD_DI);
	ClrPin(GLCD_RW);

	SetPin(GLCD_E);
	DelayUs(100);
	ClrPin(GLCD_E);
}
unsigned char GLCD_Read(void){
	unsigned long tmp;
	SetPin(GLCD_E);
	tmp = (IOPIN & (~GLCDPORT));
	tmp &= 0x000000FF;
	ClrPin(GLCD_E);
	return tmp;
}
unsigned char GetPin(unsigned long tPin){
	unsigned long tmp;
	tmp = (IOPIN & (1<<tPin));
	if(tmp == 0)
		return 0;
	else
		return 1;
}
void SetPin(unsigned long tPin){
	IOSET = 1<<tPin;
}
void ClrPin(unsigned long tPin){
	IOCLR = 1<<tPin;
}
void Wait_Not_Busy(void){
unsigned long CS1Dat;
unsigned long CS2Dat;
unsigned long stat;

 	ClrPin(GLCD_DI);
	SetPin(GLCD_RW);

	CS1Dat = GetPin(GLCD_CS1);
	CS2Dat = GetPin(GLCD_CS2);

	if (CS1Dat==1 && CS2Dat==1){
			SetPin(GLCD_CS1);
			do
			{
				SetPin(GLCD_E);
				DelayUs(1);
				stat = GLCD_Read();
				ClrPin(GLCD_E);
			}while(stat==0x80 || stat==0x10);
			SetPin(GLCD_CS1);
			ClrPin(GLCD_CS1);
	}
	else{
		do
		{
			SetPin(GLCD_E);
			DelayUs(1);
			stat = GLCD_Read();
			ClrPin(GLCD_E);
		}while(stat==0x80 || stat==0x10);
	}
}

void ClearScreen(char normal){
unsigned char x;
unsigned char y;

unsigned char FILL;
	GLCD_Write_Cmd(0x40);	
	GLCD_Write_Cmd(0xB8);

	if(normal == 0)
		FILL = 0x00;
	else
		FILL = 0xFF;

	ClrPin(GLCD_CS1);
	ClrPin(GLCD_CS2);

	for(y=0;y<8;y++)		//page loop
	{
		GLCD_Write_Cmd((0xB8 + y));
		for(x=0;x<64;x++){	//y loop
			GLCD_Write_Data(FILL);
		}
	}

	GLCD_Write_Cmd(0x40);		//go to left side
	GLCD_Write_Cmd(0xb8);		//go to top page

}

void initGLCD(void){
	SetPin(GLCD_RS);
	ClrPin(GLCD_E);

	GLCD_Write_Cmd(0x3F);	
	GLCD_Write_Cmd(0xC0);	

	ClearScreen(0);
}

int main(void){
	PINSEL0 = 0x00000000;
	IODIR = 0xFFFFFFFF;

	initGLCD();

	while(1){

	}

}
Attached Thumbnails
ARM Cortex-cls.jpg  

Last edited by AtomSoft; 23rd June 2009 at 12:12 PM.
AtomSoft is offline  
Old 23rd June 2009, 01:22 PM   #74
Default

not sure how your program or the controller works, but isn't RS the same as DI (Data or instruction)? pin P0.8 (GLCD_RS) isn't connected to anything, though it is defined to pin 8 - DI is on pin 11. so maybe you change RS to pin 11 too or fix the program for the inconsistency.

otherwise, try to step through ClearScreen() to see what's going on.
millwood is offline  
Old 23rd June 2009, 02:08 PM   #75
Default

Ill try to step through it but RS and DI are the same. My GLCD is using DI not RS. That RS was meant to be RST (reset) i ended up tie-ing it to VCC. i just forgot to take that out but it doesnt affect anything i think
AtomSoft is offline  
Reply

Tags
arm, cortex

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
ARM Cortex Microcontrollers? dknguyen Micro Controllers 0 10th February 2009 12:37 AM
ARM Cortex-M3 DSP dknguyen Micro Controllers 1 2nd February 2009 04:47 PM



All times are GMT. The time now is 05:15 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker