Hello,
Before trying to let one =B5C talk with another, I would verify that each=
=20
one can transmit and receive with a terminal.
It means connecting them in turn to a PC with a terminal programme, like =
=20
minicom on Linux or Hyperterminal on Windows, or anything better (have a =
=20
look at SuperTerm (www.mpfreezone.com) or realterm), which should not be =
=20
difficult ;-) trough a TTL-RS232 interface (MAX232 or the like).
I am not sure that your =B5C doesn't need a pullup on the RX and TX lines=
.
Anyway, try with pull-ups (10K); it can't hurt.
When you the 2 =B5C work with the terminal, you can try and connect them =
=20
together.
Regards
Jean-Paul
BTW: an 8051 is no PIC; both are microcontroller :-)
On Wed, 14 Sep 2005 17:12:26 -0500, Ruben Dario Porras Sanchez =20
<rporrass@...> wrote:
> I have 2 pics 89c52 (8052 - 8051). i need to send from one to another =20
> some
> information. i'm using the serial port but when
> i've tried to ensamble the circuit the results are not like i want.
>
> here is the code for the pic #1 program, the master:
>
> /**********************************************************************=
*************************************/
>
>
> #include <8052.h>
> #include "serial.h"
> #include <stdio.h>
>
> //procedimientos del juego
> void inicializar();
> void visualizar_display(char,long,bit,bit);
> void restraso();
> void capturar_entradas() interrupt 0;
> void descargar_salidas() interrupt 1;
>
> #define V 1
> #define F 0
>
> #define direccion_local 0x01
> #define display_credito 0x02
> #define display_apuesta 0x03
> #define display_doblada 0x04
> #define display_noapostado 0x05
> #define display_nopremio 0x06
> #define display_premio 0x07
>
> //variables del juego
> long total_entradas, total_salidas;
> long creditos, ganado;
> float pozo_juego, pozo_doblada;
> unsigned int numero_juego;
> unsigned char porcentaje_pago[]=3D{65, 70, 75, 80, 85, 90};
> unsigned int tabla_premios[][]=3D{{400, 50}, {500, 60}, {600, 60}, {700=
, =20
> 70},
> {800, 80}};
> unsigned char tabla_apuestas[]=3D{1, 2, 3, 4, 5, 10, 15, 20, 30, 40, 50=
, =20
> 60,
> 70, 80, 90, 100};
> unsigned char creditos_por_pulsos[]=3D{1, 2, 5, 10, 20, 25, 50, 100};
> unsigned char apuesta, valor_credito, ind_apuesta;
> unsigned char error;
>
> sbit at 0x92 btnN1;
> sbit at 0x93 btnN2;
> sbit at 0x94 btnN3;
> sbit at 0x95 btnDbl1;
> sbit at 0x96 btnDbl2;
> sbit at 0x97 btnDbl;
> sbit at 0xA6 btnIniciar;
> sbit at 0xA7 btnApuesta;
> sbit at 0xB2 swEnt;
> sbit at 0xB3 swSal;
> sbit at 0xB4 swLlave;
> sbit at 0xA0 swPago0;
> sbit at 0xA1 swPago1;
> sbit at 0xA2 swPago2;
> sbit at 0xA3 swPremio0;
> sbit at 0xA4 swPremio1;
> sbit at 0xA5 swPremio2;
> sbit at 0xB5 swCred0;
> sbit at 0xB6 swCred1;
> sbit at 0xB7 swCred2;
>
> void main (void){
> inicializar();
> while(1){
> while(error=3D=3D0){
> visualizar_display(display_premio,ganado,F,F);
> visualizar_display(display_credito,creditos,F,V);
> visualizar_display(display_apuesta,tabla_apuestas[ind_apuesta],F,V);
> visualizar_display(display_doblada,0,F,F);
> visualizar_display(display_noapostado,0,V,V); //cambiar el numero por l=
a
> variable
> visualizar_display(display_nopremio,0,V,V); //cambiar el numero por la
> variable
> }
> }
> }
>
> void retraso(){
> unsigned char i;
> P1=3Dind_trama;
> for(i=3D0;i<255;i++){
> }
> }
>
> void inicializar(){
> char i;
>
> //inicializacion de las interrupciones
> ET0=3D0; //desactiva la interrupcion del TIMER 0
> ET1=3D0; //desactiva la interrupcion del TIMER 1
> ET2=3D0; //desactiva la interrupcion del TIMER 2
> EX0=3D1; //activa la interrupcion externa 0 INT0
> EX1=3D1; //activa la interrupcion externa 1 INT1
> cfg_pto_serial(); //configura el puerto serial
> EA=3D1; //activa las interrupciones
>
>
> //inicializacion de las variables
> total_entradas=3D0;
> total_salidas=3D0;
> creditos=3D0;
> ganado=3D0;
> ind_apuesta=3D0;
> numero_juego=3D0;
> pozo_juego=3D3000;
> pozo_doblada=3D1500;
> error=3D0;
> apuesta=3Dtabla_apuestas[ind_apuesta];
>
> //inicializacion de los displays
> for(i=3D0;i<10;i++){
> visualizar_display(display_premio,i,V,V);
> visualizar_display(display_credito,i,V,V);
> visualizar_display(display_apuesta,i,V,V);
> visualizar_display(display_doblada,i,V,V);
> visualizar_display(display_noapostado,i,V,V);
> visualizar_display(display_nopremio,i,V,V);
> retraso();
> }
> }
>
> void visualizar_display(char display, long numero, bit ceros, bit =20
> ultDig){
> unsigned char bufferEnv[]=3D{0xff, 0xff, 0xff};
> unsigned char i,k,vartmp;
>
> k=3D-1;
> for(i=3D0;i<6;i++){
> vartmp=3D(unsigned char)numero%10;
> if(i%2!=3D0){
> vartmp=3Dvartmp<<4;
> vartmp=3Dvartmp&0xf0;
> }
> else{
> vartmp=3Dvartmp&0x0f;
> k++;
> }
> if((numero=3D=3D0)&&(ceros=3D=3DF)){
> vartmp=3D0xff;
> }
> bufferEnv[k]=3DbufferEnv[k]|vartmp;
> numero=3Dnumero/10;
> }
> if((ultDig=3D=3DV)&&(bufferEnv[0]=3D=3D0xff)){
> bufferEnv[0]=3D0;
> }
> enviar_comando(display,0,bufferEnv);
> }
>
> void capturar_entradas() interrupt 0{
> unsigned char vartmp=3DP3>>5;
> valor_credito=3Dcreditos_por_pulsos[vartmp];
> creditos=3Dcreditos+valor_credito;
> total_entradas=3Dtotal_entradas+valor_credito;
> }
>
> void descargar_salidas() interrupt 1{
> total_salidas=3Dtotal_salidas+creditos;
> creditos=3D0;
> }
>
>
> /**********************************************************************=
*************************************/
>
>
> this is the code for the pic #2, the slave:
>
> /**********************************************************************=
*************************************/
>
>
> #include <8052.h>
> #include "serial.h"
> #include <stdio.h>
>
> //procedimientos
> void inicializar();
>
> #define V 1
> #define F 0
>
> #define direccion_master 0x01
> #define direccion_local 0x02
>
> //variables
> unsigned char error;
>
> void main (void){
> inicializar();
> while(1){
> while(error=3D=3D0){
> if(ind_trama=3D=3D4){
> //el comando es para mi
> if(trama[0]=3D=3Ddireccion_local){
> P2=3Dtrama[2];
> }
> ind_trama=3D0;
> }
> P1=3Dind_trama;
> }
> }
> }
>
> void inicializar(){
> //inicializacion de las interrupciones
> ET0=3D0; //desactiva la interrupcion del TIMER 0
> ET1=3D0; //desactiva la interrupcion del TIMER 1
> ET2=3D0; //desactiva la interrupcion del TIMER 2
> EX0=3D0; //activa la interrupcion externa 0 INT0
> EX1=3D0; //activa la interrupcion externa 1 INT1
> cfg_pto_serial(); //configura el puerto serial
> EA=3D1; //activa las interrupciones
>
>
> //inicializacion de las variables
> error=3D0;
> ind_trama=3D0;
> }
>
>
> /**********************************************************************=
*************************************/
>
>
> this is the include serial.h:
>
> /**********************************************************************=
*************************************/
>
>
> #include <8052.h>
>
> unsigned char ind_trama, trama[5];
>
> void cfg_pto_serial(){
> SCON=3D0xF0; //uart en modo 3 (9 bit), REN=3D1
> TMOD=3DTMOD|0x20; //Timer 1 en modo 2
> TH1=3D0xFD; //19200 Bds
> TL1=3D0xFD; //19200 Bds
> ES=3D1; //activa la interrupcion del PUERTO SERIAL
> TR1=3D1; //correr el Timer 1
> }
>
> void puerto_serial_event() interrupt 4{
> if(TI=3D=3D1){ //si envia datos
> TI=3D0; //limpia la bandera de transmision
> }
>
> if (RI=3D=3D1){ //si recibe datos
> RI=3D0; //limpia la bandera de recepcion
> if(RB8){
> SM2=3D0; //modo de datos 2
> }
> else{
> ind_trama++;
> if(ind_trama>4){
> ind_trama=3D0;
> }
> trama[ind_trama]=3DSBUF;
> SM2=3D1; //modo de datos 1
> }
> }
> }
>
> void enviar_comando(unsigned char direccion, unsigned char comando, =20
> unsigned
> char parametros[3]){
> unsigned char i;
> SBUF=3Ddireccion;
> while(TI=3D=3D1);
> SBUF=3Dcomando;
> while(TI=3D=3D1);
> for(i=3D0;i<3;i++){
> trama[2+i]=3Dparametros[i];
> while(TI=3D=3D1);
> }
> }
>
>
> in the circuit i've put the pins 40 and 31 to 5v, 20 to GND, the pin 10
> (RXD) of the master (pic #1) to the pin 11 (TXD) of
>
> the slave (pic #2) and the pin 11 (TXD) of the master to pin 10 of the =
=20
> slave
> (RXD). the pins 21 to 28 are conecteds to 7447.
> i'm using the SUPERFROM/Z to program the at89c52, i've opened the
> juego.ihxin intel hex format file and program the at89c52. the same
> for
> display.ihx.
>
> i'll appreciate any help thanks,
--=20
NEVER jump into a LOOP!
|