Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

help with AT89S52

2012-07-05 by alex_p_silva

Could someone help me I'm trying to make a serial with AT89S52 but they are funny characters and not real (test simulator proteus)


Could someone help me I'm trying to make a serial with AT89S52 but they are funny characters and not real (test simulator proteus)

My code is as follows if anyone can tell what I'm doing wrong, I'm with 12MHz oscillator, I want a baud rate of 9600 even 1 


include <at89x52.h>

volatile char acceptext;
volatile __bit status=0;

void IntSerial()__interrupt 4 __using 1
{
ES=0;
RI=0;
status = 1;
acceptext = SBUF;
ES=1;
}


void inituart(void)   // serial port initialization
{
SCON = 0x50; // uart in mode 3
//PCON = 0x00;
TMOD =  0X20; // timer 1 in mode2
TH1 = 0xfd  ;// setting baudrate 9600 bps
//TL1 = 0xfd;
ES=1        ; // enable serial interrupt 
EA = 1      ; // enable global interrupt
TR1 = 1      ; // start timer 1 running
}

void sendchar(char datasent) // for sending one charater
{
   SBUF = datasent;
   while (!TI)
   {;}
   TI = 0;
} 

void sendtext(char *text) //for sending text
{
  char i=0;
  while (text[i]!=0)
 {
  sendchar(text[i]);
  i++;
  }
  sendchar(13);
  sendchar(10);
}

void delay100ms()
{
	__asm
	push ACC
	mov a,#149
L0:	
	push ACC
	mov a,#170
L1:
	nop
	nop
	djnz acc,L1
	nop
	nop
	pop ACC
	djnz acc,L0
	nop
	pop ACC
	__endasm;
}


void main(void)
{
   inituart();
   while (1){
   sendtext("TRIAL 1");
   P1=0X50;
P2=0X50;
delay100ms();
P1=0X00;
P2=0X00;
delay100ms();}
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.