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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/01/10 03:14
Read: times


 
#177553 - Basic program
I always used PIC microcontrollers, but now I need to do a project using the 89C2051. I made a small program to test, but it is not working. Not even is set a pin. I used the free version of uVision. Can you tell me what's wrong with this code?
#include <variaveis.c>

void trata_serial(void)
{
	if(buff_rx[0] == S)
	{		
		if(buff_rx[1] == M)
		{
			if(buff_rx[2] == 0)
			{
				if(buff_rx[3] == 1)
				{
					buff_tx[0] = S;
					buff_tx[1] = M;
					buff_tx[2] = (char)pulsos>>8;
					buff_tx[3] = (char)pulsos;
					byte_tx = 3;
					send_mb();
					byte_rx = 0;
				}
			}
		}
	}
}
void com_initialize (unsigned int baudrate)
{		 
	com_baudrate (baudrate);

	EA = 0; 
	SM0 = 0; SM1 = 1;
	SM2 = 0;
	REN = 1;		
	
	TI = 0;		
	RI = 0;		
	
	ES = 1;		
	PS = 0;		
	
	EA = 1;     
}

void com_baudrate (unsigned int baudrate)
{
	EA = 0;       	
	
	TI = 0;			
	
	TR1 = 0;		
	ET1 = 0;		
	
	PCON |= 0x80;
	
	TMOD &= ~0xF0;
	TMOD |= 0x20;
	
	TH1 = (unsigned char) (256 - (XTAL / (16L * 12L * baudrate)));
	
	TR1 = 1;
	
	EA = 1; 
}				

static void recebe_serial(void) interrupt 4
{	
	if (RI != 0)
  	{
 		RI = 0;
		
			buff_rx[byte_rx]=SBUF;
			byte_rx++;
			if(byte_rx == 4)
			{
				Frecebido = 1;
			}
		timeout_mb = 0;
	}
}

void send_mb()
{
		unsigned char No_byte_tx = byte_tx;
		for(byte_tx=0;No_byte_tx>=0;No_byte_tx--)//envia bytes pela serial
		{
			SBUF =  buff_tx[byte_tx++];
		}
}

void int_initialize(void)
{
	EA = 0;

	IT0 = 1;

	EA = 1;
}

void int0_flow(void) interrupt 0
{
	pulsos++;
}

void timer_initialize (void) //1,8ms
{
	EA = 0;             
		
	TR0 = 0;			
	ET0 = 1;			
	
	TMOD &= ~0xF;		
	TMOD |= 0x01;		
	
	TH0 = 0xFA;
	TL0 = 0x24;
	
	TR1 = 1;			
	
	EA = 1;             
}	

void timer_flow(void) interrupt 1
{		
	timeout_mb++;
	if(timeout_mb == 50)
	{
		unsigned char No_byte_rx = byte_rx;
		for(byte_rx=0;No_byte_rx!=0;No_byte_rx--)
		{
			buff_rx[byte_rx] = 0;
		}		
		timeout_mb = 0;
	}	

	count++;

	if(count > 1000)
	{
		count = 0;
		if(P1_6)
		{
			P1_6 = 0;
		}
		else
		{
			P1_6 = 1;
		}
	}
}
void main (void)
{
	com_initialize (19200);
	timer_initialize(); 
	int_initialize();
	P1_5 = 1;

	while (1)
	{		
		if(Frecebido)
		{
			trata_serial();
		}
	}
}

 



List of 10 messages in thread
TopicAuthorDate
Basic program            01/01/70 00:00      
   Start simple            01/01/70 00:00      
      they are            01/01/70 00:00      
   Check Keil site            01/01/70 00:00      
      Daniel hit thre nail on the head            01/01/70 00:00      
   Thank you            01/01/70 00:00      
      LJMP / 0x800 Not A Problem            01/01/70 00:00      
         Missing link - Assembler            01/01/70 00:00      
            Completing the sentence....            01/01/70 00:00      
   I used the free (sic) version of uVision            01/01/70 00:00      

Back to Subject List