Página 1 de 1

Mais seriais em um 8051

MensagemEnviado: 08 Nov 2006 13:01
por Alexandro
Alguem sabe como posso fazer 2 portas seriais de 9600 em um 89S53 via software ? Programo em C !

Thanks

MensagemEnviado: 08 Nov 2006 13:41
por ftegon
Ola!

O melhor seria usar um microcontrolador com dois canais seriais.

ex. Dallas Maxim 80C320 (sem flash) ou Winbond W77E516 (com flash e ISP).

Por software tem uma apnote da Siemens (ap083101) com o titulo
Emulating an asynchonous serial interface (USART) via software routines.

Obs. Nunca usei , mas é em C e tem o fonte, acho que vale a pena dar uma olhada.

Até +

Fabio Tegon

MensagemEnviado: 08 Nov 2006 14:48
por brasilma
Conversamos sobre isso agorinha a pouco: http://www.asm51.eng.br/phpbb/viewtopic ... ght=serial

Tente utilisar o sistema de busca do forum antes de abrir um novo tópico, leia tudo que encontrar, e persistindo alguma dúvida, "grite".

MensagemEnviado: 08 Nov 2006 15:18
por Alexandro
Valeu pessoal.

MensagemEnviado: 08 Nov 2006 15:41
por ftegon
Ola!

Tornando a resposta um pouco mais generica:

Há diversas formas de ter uma segunda serial em um microcontrolador da familia 8051 :

1° ) A mais fácil, utilizar um microcontrolador com 2 canais seriais:

80C320, W77E58, W77E516, W77E532, etc...

2°) Colocar uma U(S)ART a mais no circuito:

A aplicação permite endereçamento externo

UARTS industriais (9bits) SCC2691, SCC2692, etc ...
UARTS comuns 82C50, 16C550, SCC2681, etc...

A aplicação não permite endereçamento externo

UARTS via SPI , MAX3100, MAX3110E, MAX3111E, etc...

3º) Por software:

Via BIT-BANG.

Vantagem: implementação simples (rotinas geralmente em ASM)
*
* "Bit-bang" serial I/O functions for the 8051.
*
* These routines transmit and receive serial data using two general
* I/O pins, in 8 bit, No parity, 1 stop bit format. They are useful
* for performing serial I/O on 8051 derivatives not having an
* internal UART, or for implementing a second serial channel.
*
* Dave Dunfield - May 17, 1994
*
* NOTE that R0 and R1 are used by the functions. You may wish to
* add PUSH/POP instructions to save/restore these registers.
*
TXD EQU P1.0 Transmit on this pin
RXD EQU P1.1 Receive on this pin
* The serial baud rate is determined by the processor crystal, and
* this constant which is calculated as: (((crystal/baud)/12) - 5) / 2
BITTIM EQU 45 (((11059200/9600)/12) - 5) / 2
*
* Transmit character in A via TXD line
*
putc CLR TXD Drop line for start bit
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For START bit
MOV R1,#8 Send 8 bits
putc1 RRC A Move next bit into carry
MOV TXD,C Write next bit
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For DATA bit
DJNZ R1,putc1 write 8 bits
SETB TXD Set line high
RRC A Restore ACC contents
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For STOP bit
RET
*
* Receive a character from the RXD line and return in A
*
getc JB RXD,* Wait for start bit
MOV R0,#BITTIM/2 Wait 1/2 bit-time
DJNZ R0,* To sample in middle
JB RXD,getc Insure valid
MOV R1,#8 Read 8 bits
getc1 MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For DATA bit
MOV C,RXD Read bit
RRC A Shift it into ACC
DJNZ R1,getc1 read 8 bits
RET go home

Desvantagem: sobrecarga do microcontrolador.

Via Interrupção:
Vantagem: menor sobrecarga do microcontrolador (rotinas em C) Siemens apnote AP083101
Desvantagem: utiliza interrupção externa.


Bom agora você pode escolher o que melhor atenda a sua aplicação.


Até +

Fabio Tegon