Hi All, I have a problem with this code: This simple code sends 0-255 with 9600 baudrate to pc and P2 port My problem is in loop runtime . program crashes when arrived to line :P2=i. so we see '0' only on hyperterminal . I changed type of 'i' to int , but the result remains . All The Best Aziz #include <w78e65.H> #include <stdio.h> main() { unsigned char i; TMOD=0x20; SCON=0x52; TH1=0xfa; TR1=1; for(i=0;i<=255;i++) { printf("%d",i); P2=i; } } /**************************************/
Dear eduard, Regards, Unfortunately , I have mistaked in my codes in forum . Please kindly take this : include <w78e65.H> #include <stdio.h> main() { unsigned char i; TMOD=0x20; SCON=0x52; TH1=0xfa; TR1=1; for(i=0;i<=255;i++) { printf("%bd",i); P2=i; } } /**************************************/
Dear Aziz. OK. You must reorganize program. It is OK. include <w78e65.H> #include <stdio.h> main() { unsigned char i; TMOD=0x20; SCON=0x52; TH1=0xfa; TR1=1; while(1) { for(i=0;i<=255;i++) { printf("%bd",i); P2=i; } } }
Dear Aziz. Ooops. At P2 is high addres for external memory CODE, or RAM. If have ext. CODE or RAM then program must crash if You change state P2 ...... Eduard Jadron
Dear Eduard, No ex. chip has applied . The design is a simple & bare circuit !
You must reorganize program. It is OK. No need to, actually. The for() loop is infinite already as it is. No need thus to loop a while(1) around it avoid falling out of main().
Dear Hans, Regards, This fault have overcame with a delay loop after main() and variable definitions ! Like this : #include <w78e65.H> #include <stdio.h> main() { unsigned char i; for(i=0;i<100;i++) //Delay TMOD=0x20; SCON=0x52; TH1=0xfa; TR1=1; for(i=0;i<=255;i++) { printf("%bd",i); P2=i; } } /**************************************/ Can you tell me why ?
main() { unsigned char i; for(i=0;i<100;i++) //Delay
Dear Hans , My operation clock is 22.1184 MHZ The circuit is simple consist of a cpu and crystal and max232 reducing the 100 caused hanging again ! I checked the serial port . It was OK .
I've seen this before. The MAX chip takes quite a while to pump up its +9/-9V supplies, so you need to wait for it.