CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS232 interrupt problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jchait



Joined: 06 Jun 2004
Posts: 3

View user's profile Send private message

RS232 interrupt problems
PostPosted: Sun Jun 06, 2004 4:42 am     Reply with quote

Can anybody see what is wrong with this program?
It should toggle the RB1 every 1msec or so.
If I assign port D pins as inputs, it works fine, but if I assigned as outputs, it does not.
I’m using version 3.179

Any ideas?

Thanks

Jaime

///////////////////////////////////////////////////////////////////////////
#include <18F452.H>

#device *=16
#device ADC=10
#fuses H4, NOWDT, NOPROTECT, PUT , NOLVP

#use delay(clock=40000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#bit TST_PT = 0xF81.1

char RX_buffer[256];
int endbuf, startbuf;

#int_rda
void serial_isr() {
TST_PT = !TST_PT;
RX_buffer[endbuf++]=getc();
endbuf &= 0xFF;
}

void main(void)
{
set_tris_b(0x00); // All outputs
set_tris_c(0xBF); // All inputs except TX (RC6)

set_tris_d(0xFF); // Port D as input (WORKS)
// set_tris_d(0x00); // Port D as output (DOES NOT WORK)

endbuf = 0; // SETUP RX_RS232
startbuf = 0;

enable_interrupts(int_rda);
enable_interrupts(global);
while (1) {
}

}
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sun Jun 06, 2004 4:59 am     Reply with quote

Just a quick note: The binary NOT operator in C is ~ not !. Also, you can use the function output_toggle(). Try the following lines and see if it makes a difference:

TST_PT = ~TST_PT;

And

output_toggle(PIN_D1);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 06, 2004 3:36 pm     Reply with quote

Quote:
Can anybody see what is wrong with this program?
It should toggle the RB1 every 1msec or so.
If I assign port D pins as inputs, it works fine, but if I assigned as outputs, it does not.


1. It would toggle only if you have continuous incoming chars on the
Rx pin. Do you ?

2. One question would be, what do you have connected to Port D ?

3. Also, I would add the ERRORS directive to the end of the #use rs232
statement.

4. I would also get rid of the 4x PLL mode while testing this problem.
Go to 10 MHz normal operation.
jchait



Joined: 06 Jun 2004
Posts: 3

View user's profile Send private message

Fixed
PostPosted: Sun Jun 06, 2004 7:11 pm     Reply with quote

Thanks Haplo, but using “~” nor out_toggle() helped. (It is a good practice to start using the right operator though).

To PCM programmer.
1) Yes, I send a long file (300K) via RS232 using a terminal program (Tera-term and the Send function). So I can see the 500 Hz square wave as long as the file is being transferred.
2) Nothing is connected to port D
3) Good idea
4) Good idea.

I did replace the 452 by a 458 and things started working the way it supposed to.
I compared the LST files and they do not match 100% but very close (I’m including these parts bellow). So I don’t know if there was something wrong with that particular 452 or ?????

Any ways.

Thanks for your input.

Jaime



PIC18F452
.................... void main(void)
.................... {
00BE: NOP(FFFF)
00C0: CLRF FF8
00C2: BCF FD0.7
00C4: BSF 0D.7
00C6: CLRF FEA
00C8: CLRF FE9
00CA: MOVLW 06
00CC: MOVWF FC1
00CE: MOVLW 40
00D0: MOVWF FAF
00D2: MOVLW 22
00D4: MOVWF FAC
00D6: MOVLW 90
00D8: MOVWF FAB
.................... set_tris_b(0x00); // All outputs
00DA: MOVLW 00
00DC: MOVWF F93
.................... set_tris_c(0xBF); // All inputs except TX (RC6)
00DE: MOVLW BF
00E0: MOVWF F94
....................
.................... // set_tris_d(0xFF); // Port D as input (OK)
.................... set_tris_d(0x00); // Port D as output (not OK)
00E2: MOVLW 00
00E4: MOVWF F95
....................
.................... endbuf = 0; // SETUP RX_RS232
00E6: MOVLB 1
00E8: CLRF x17
.................... startbuf = 0;
00EA: CLRF x18
....................
.................... enable_interrupts(int_rda);
00EC: BSF F9D.5
.................... enable_interrupts(global);
00EE: MOVLW C0
00F0: IORWF FF2,F
.................... while (1) {
.................... }
00F2: GOTO 00F2
....................
.................... }
....................
00F6: SLEEP

Configuration Fuses:
Word 1: 2600 H4 NOOSCSEN
Word 2: 0E0E BROWNOUT WDT128 NOWDT BORV20 PUT
Word 3: 0100 CCP2C1
Word 4: 0081 STVREN NODEBUG NOLVP
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTB NOWRTC
Word 7: 400F NOEBTR NOEBTRB


PIC18F458
.................... void main(void)
.................... {
00BE: NOP(FFFF)
00C0: CLRF FF8
00C2: BCF FD0.7
00C4: BSF 0D.7
00C6: CLRF FEA
00C8: CLRF FE9
00CA: MOVLW 06
00CC: MOVWF FC1
00CE: MOVLW 07
00D0: MOVWF FB4
00D2: MOVLW 40
00D4: MOVWF FAF
00D6: MOVLW 22
00D8: MOVWF FAC
00DA: MOVLW 90
00DC: MOVWF FAB
.................... set_tris_b(0x00); // All outputs
00DE: MOVLW 00
00E0: MOVWF F93
.................... set_tris_c(0xBF); // All inputs except TX (RC6)
00E2: MOVLW BF
00E4: MOVWF F94
....................
.................... // set_tris_d(0xFF); // Port D as input (OK)
.................... set_tris_d(0x00); // Port D as output (not OK)
00E6: MOVLW 00
00E8: MOVWF F95
....................
.................... endbuf = 0; // SETUP RX_RS232
00EA: MOVLB 1
00EC: CLRF x17
.................... startbuf = 0;
00EE: CLRF x18
....................
.................... enable_interrupts(int_rda);
00F0: BSF F9D.5
.................... enable_interrupts(global);
00F2: MOVLW C0
00F4: IORWF FF2,F
.................... while (1) {
.................... }
00F6: GOTO 00F6
....................
.................... }
....................
00FA: SLEEP

Configuration Fuses:
Word 1: 2600 H4 NOOSCSEN
Word 2: 0E0E BROWNOUT WDT128 NOWDT BORV20 PUT
Word 3: 0000
Word 4: 0081 STVREN NODEBUG NOLVP
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTB NOWRTC
Word 7: 400F NOEBTR NOEB
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group