Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 serial transmission...

Status
Not open for further replies.

blacksnow

Junior Member level 2
Joined
Mar 1, 2010
Messages
20
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
India
Activity points
1,432
I developed a pulse counter using external interrupt (using software counter) which is working fine and showing the desired result on LCD in proteus. Now i want to send each incremented count to serial port but this is not working. My code is the following, (please give me some suggestion to rectify the problem).

void serial_ISR () interrupt 4 {
if(TI){
TI = 0;
for (p=0; p<=s; p++){
SBUF = digit[p];
}
}

void EX1_ISR () interrupt 2 {
if(k<177){
k = k + 1; //k is global
ind = 0; // for LED indication
}
else
ind = 1;
LCD_DISPLAY(k); // LCD function
}

void main(void){
.....
....
.....
while(1){

split2dig(k); // for sending individual digit

}
}

void split2dig(unsigned int val)
{
unsigned int val1, den = 10000;
s = 0; // global

while (den!=0){
digit = (char)(val1/den);
digit = digit + 48;
val1 = val%den;
den = den / 10;
s = s + 1;
}

}
 

Thanks a lot. I will check the posted link and then will give you some response.
 

void serial_ISR () interrupt 4 {
if(TI){
TI = 0;
for (p=0; p<=s; p++){
SBUF = digit[p];
}
}
your code try to send an array in interrupt routine itself. try sending a single byte from interrupt routine at a time.
 

Thats a good point to hint.
Always make ur ISR code as small as possible.
--
Amr
 

what i meant here is that this interrupt routine will cause a request to it self as soon as a byte is transfered. thus it will overflow stack.

even if your array is small say of index=3, you must take into account the max level of stack at any point in your code. also you must make it reentrant function.

even then you can't be sure of your code as it is difficult to say anything about max level of stack at any point in your code as your code gets more complex.

thus it would be advisable to send a single byte in isr routine.
 

Thats not true my friend.
--
Amr
 

@amraldo

clear me if i am wrong.

thanks
 

I guess to have an interrupt firing another interrupt is not a good practice after all.
Please, revise the library I pointed to earlier.
--
Amr
 

himrwt said:
void serial_ISR () interrupt 4 {
if(TI){
TI = 0;
for (p=0; p<=s; p++){
SBUF = digit[p];
}
}
your code try to send an array in interrupt routine itself. try sending a single byte from interrupt routine at a time.

It worked for me by sending just a single byte at a time. Thanks a lot for your important hint.

Thanks again...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top