Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/17/08 09:43
Modified:
  10/17/08 11:08

Read: times


 
Msg Score: -1
 -1 Non-Specific question
#159144 - Help with code for 89S52
I need suggestion for the following code!
Will they work?
this code is used for schematic given on
my page http://www.8052.com/users/milem/

If any have code for that schematics that will be best!
Best regards!
P.S.
Difference between schematics and test board is on used ports
and number of transistors used for charging transistors (used only 4 on P1.0 - P1.3 and P1.4 used for discharging transistor)

Main question is will interrupt 0 will execute like I wrote!


#include <REG52.h>

#define uchar unsigned char
#define uint unsigned int

uchar pozicija,emask;
const uchar code ascii_table[] = {//acii code for display}

uchar vert, display[4],maska;

bit too_big, too_short,has_result;
uint rezultat;

void Init(void)
{
	ET0=1;
	IT0=1;
	emask=1;
	TMOD=(TMOD & 0x0F)|0x09;
	ET2=1;
	EA=1;
	RCAP2L=TL2=0x00;
	RCAP2H=TH2=0xF0;
	TR2=1;
	vert=0;
	maska=1;
}


void Clear(void)
{
	ET0=0;
	EX0=0;
	P1=0xFF; //activate discharging transistor
	while(INT0==1){}//wait while is set to zero
	TH0=0;TL0=0;
	P1=0xF7; //deactivate discharging transistor
}

void Execute(void)
{
	ET0=1; EX0=1;
	P2=~emask & 0xF7;
 
}

void Timer0_Overload(void) interrupt 1 ?is this correct
{
too_big=1;
EX0=0;
EX1=0;
}
void Timer0_External(void) interrupt 0
{
	rezultat=256*TH0+TL0;
	if(rezultat>0x0F)
	{
		has_result=1;
		Clear();
	}
	else
	{
		too_short=1;
	}
}

void write_char(uchar d,uchar pos)
{
	display[pos]=~ascii_table[d-0x20];	
}

void write_string(uint *d)
{
uchar i=0;
TR2=0;
	while(i<4)
	{
		write_char(*d,i);
		d++;
		i++;
	}
}


void Refresh_displej(void) using 2 	
{						
	TF2=0;				
	P2=0x00;
 	P0=~0xff;
	vert++;
	P0=~display[vert];
	if(vert>4)
	{
		vert=0;
		maska=1;
	}
	P2=maska;
	maska<<=1;
}

void prekidT2 (void) interrupt 5 using 2
{
	Refresh_displej();
}

void get_tast(void) //function for read what taster is pressed (not implemented yet not need now)
{
}

void main(void)
{
	Init();
	while(1)
	{
		if(get_tast()==1) Execute();
		if(has_result==1) { //Calculating }
		if(too_short==1) 
		{
			emask>>=1;
			too_short=0;
			Clear();
			Execute();
		}
		if(too_big==1)
		{
			too_big==0;
			Clear;
                        //code for stop
		}
	}
}


List of 3 messages in thread
TopicAuthorDate
Help with code for 89S52            01/01/70 00:00      
   Will they work?            01/01/70 00:00      
   Port0            01/01/70 00:00      

Back to Subject List