romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 void serial_init() { TMOD = 0x20; //enable timer1 / mode 2 / 8-bit auto-reload SCON = 0x50; //Serial port mode bit 1 / 8 bit. / Receiver Enable. TH1 = 0xFD; // generate 9600 baudrate TL1 = 0xFD; TR1 = 1; //start timer 1 } void serial_send(unsigned char dat) { SBUF = dat; // Store data in sbuf while(TI==0); // Wait till data transmit TI=0; }
Code ASP - [expand] 1 2 3 4 5 6 void main() { serial_init(); serial_send('r'); while(1); }
Hello
As per your code there is must be no problem,one thing -
no neeed to initialize TL1.
check out the baud rate and port settings in the hyperterminal.If that doesn`t solve the problem then post the whole code so that we can find any bugs if any.
check your hyperterminal settings ... or restart the system, .. Are you sure your system does not have virus??????
check your hyperterminal settings ... or restart the system, .. Are you sure your system does not have virus??????
check your hyperterminal settings ... or restart the system, .. Are you sure your system does not have virus??????
try with this
PuTTY Download Page
i got output in hyperterminal for the program.... wheck the crystal you are using and hyperterminal settings again...
9600 8-N-1 no parity..
#include<reg51.h>
void serial_init()
{
TMOD=0x20;
SCON=0x50;
TH1=0xfd;
TR1=1;
}
void main(void)
{
unsigned char var;
serial_init();
while(1)
{
while(!RI);
RI=0;
ACC=SBUF;
val=ACC;
SBUF=val;
while(!TI);
TI=0;
}
}
#include <REG51.H>
char received;
void serial_init()
{
TMOD = 0x20; //enable timer1 / mode 2 / 8-bit auto-reload
SCON = 0x50; //Serial port mode bit 1 / 8 bit. / Receiver Enable.
TH1 = 0xFD; // generate 9600 baudrate
TR1 = 1; //start timer 1
}
void serial_send(unsigned char dat)
{
SBUF = dat; // Store data in sbuf
while(TI==0); // Wait till data transmit
TI=0;
}
void serial_read()
{
while(RI == 0);
received = SBUF;
RI = 0;
}
void main()
{
serial_init();
IE = 0x90;
while(1)
{
serial_read();
serial_send(received);
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include <REG51.H> unsigned char recve; void serial_init() { TMOD = 0x20; //enable timer1 / mode 2 / 8-bit auto-reload SCON = 0x50; //Serial port mode bit 1 / 8 bit. / Receiver Enable. TH1 = 0xFD; // generate 9600 baudrate TR1 = 1; //start timer 1 } void serial_send(unsigned char send) { SBUF = send; while(TI==0); TI = 0; } void serial_read() { while(RI==0); recve = SBUF; RI=0; } void main() { P2 = 0x00; serial_init(); while(1) { serial_read(); if(recve == 'y') P2 = 0x03; // turn on output when y is received else { P2=0x00; serial_send('k'); //transmit K to serial when recieved is not y } } }
draaw the circuit in it as per your code and port pins, link the code you wrote and run it,, it will open a black window and show output when you run the program...........
---------- Post added at 18:44 ---------- Previous post was at 18:39 ----------
Proteus - APCircuits
---------- Post added at 18:46 ---------- Previous post was at 18:44 ----------
http://www.mindmodulations.com/resources/Proteus-createsession.doc
Code C - [expand] 1 2 3 4 5 void serial_sendstr(unsigned char *p) { while(*p!='\0') serial_send(*p++); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 #include <stdio.h> #include <string.h> int search(char *p[], char *name); char *names[] = {"John","Jim","Jane","James","romel",NULL}; int main() { char s1 [] = "ako si batman pangit"; char s2 [] = "hi Im romel gwapo"; char s3 [] = "ako ay gwapo kaayo"; char s4 [] = "gwapo kaayo"; //start from the first occurence of the string printf ("\n1.%s", strstr (s1,"si")); //start from the first occurence of the string //searches string from s3 to s4 /// if(strstr(s3, s4) != NULL) //searches string from s3 to s4 printf("\n2.String found: %s\n \n \n \n",s4); else printf("\n1.String NOT found \n \n \n \n"); //END searches string from s3 to s4 /// //search string inside pointer array if(search(names, "romel") != -1) printf("3.in list \n \n"); else printf("not in the list \n \n"); //end search string inside pointer array } //search string inside pointer array function int search(char *p[], char *name) { int t; for(t=0; p[t]; ++t){ if(!strcmp(p[t], name)) { return t; } } return -1; /* not found */ } //search string inside pointer array function
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?