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 support@ccsinfo.com

rs232 with 16 and 18 series
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
christian
Guest







rs232 with 16 and 18 series
PostPosted: Sun Feb 20, 2005 4:43 pm     Reply with quote

Hi, I am having a problem with serial communication using any pic18f series chip, the following code works very well for all the 16f series i have tried

------------------------------------------------------------------------------------
//#include <18F452.h>
#include <16F877A.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP

#use rs232(DEBUGGER)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=pc)


char commandstring[30];
Int i;
Int buffer[];

#int_RDA
void RDA_isr()
{
fgets(commandstring, pc);
fprintf(pc,"%s\n", commandstring);
}


void main()
{
enable_interrupts(INT_RDA); // Enable Rx interrupt
enable_interrupts(GLOBAL); // Enable Global interrupts

while(1)
{

}


}
---------------------------------------------------------------------------

this same code wont work for my pic18f452, or 18f458. If i use an external interrupt the code works except that the first charater is screwed up (as expected), but i find this to be a very lousy way to do it.

Please if you can help me find out why the 18f series wont work with the above code plz reply. Thank you in advance
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 5:10 pm     Reply with quote

I tested your code with PCH vs. 3.188 and it worked on a 18F452.
I'm running at 4 MHz, so I changed the fuse to XT.

What compiler version are you using ?
christian
Guest







PostPosted: Sun Feb 20, 2005 5:32 pm     Reply with quote

Thanks for the reply, i'm using pch vs 3.211.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 5:40 pm     Reply with quote

I don't have that version. I didn't renew the maintenance for PCH
because vs. 3.188 works OK for me. Someone else will have to
test that version for you.
Guest








PostPosted: Sun Feb 20, 2005 5:52 pm     Reply with quote

thank very much sir
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 6:28 pm     Reply with quote

If you still have download rights, you should download vs. 3.191 and
try it.
http://www.ccsinfo.com/download.shtml
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 7:18 pm     Reply with quote

Christian,
Very likely your problem is hardware related. I can't remember anyone posting an RS-232 related problem caused by the compiler recently. Can you describe the circuit connected to C6 and C7? Are you using a MAX232 or similar circuit?
Christian
Guest







PostPosted: Sun Feb 20, 2005 7:19 pm     Reply with quote

I wish i could say it was hardware related, 16f877 and 18f452 have the same pinouts, so i think its safe to rule that out Confused
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 7:28 pm     Reply with quote

Christian wrote:
I wish i could say it was hardware related, 16f877 and 18f452 have the same pinouts, so i think its safe to rule that out Confused
So the hardware can be ruled out....

I don't have v3.211 either. Can you post the list file for the 18F452 version?
Christian
Guest







PostPosted: Sun Feb 20, 2005 7:31 pm     Reply with quote

whats a list file? Confused . btw thank you for your time
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 7:40 pm     Reply with quote

Christian wrote:
whats a list file? Confused . btw thank you for your time
This is an text file generated by the compiler showing both you C-code and the generated assembly code intermixed. Very useful for debugging. I study it a lot because you will learn a lot about the compiler and programming in general; for example you can compare the results for several C contructions and see which one generates the most optimized code, etc.

This file can be found in your project directory with file extension *.lst
Christian
Guest







PostPosted: Sun Feb 20, 2005 7:59 pm     Reply with quote

-----------------------------------------------------------------------
CCS PCM C Compiler, Version 3.211, 16465 20-Feb-05 19:54

Filename: C:\Program Files\PICC\Examples\checkin.LST

ROM used: 113 words (1%)
Largest free fragment is 2048
RAM used: 45 (26%) at main() level
46 (26%) worst case
Stack: 1 worst case (0 in main + 1 for interrupts)

*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 056
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 0A,W
0009: MOVWF 20
000A: CLRF 0A
000B: MOVF 04,W
000C: MOVWF 22
000D: MOVF 77,W
000E: MOVWF 23
000F: MOVF 78,W
0010: MOVWF 24
0011: MOVF 79,W
0012: MOVWF 25
0013: MOVF 7A,W
0014: MOVWF 26
0015: MOVF 7B,W
0016: MOVWF 27
0017: BCF 03.7
0018: BCF 03.5
0019: MOVLW 8C
001A: MOVWF 04
001B: BTFSS 00.5
001C: GOTO 01F
001D: BTFSC 0C.5
001E: GOTO 032
001F: MOVF 22,W
0020: MOVWF 04
0021: MOVF 23,W
0022: MOVWF 77
0023: MOVF 24,W
0024: MOVWF 78
0025: MOVF 25,W
0026: MOVWF 79
0027: MOVF 26,W
0028: MOVWF 7A
0029: MOVF 27,W
002A: MOVWF 7B
002B: MOVF 20,W
002C: MOVWF 0A
002D: SWAPF 21,W
002E: MOVWF 03
002F: SWAPF 7F,F
0030: SWAPF 7F,W
0031: RETFIE
0032: BCF 0A.3
0033: BCF 0A.4
0034: GOTO 035
....................
.................... //#include <18F452.h>
.................... #include <16F877A.h>
.................... //////// Standard Header file for the PIC16F877A device ////////////////
.................... #device PIC16F877A
.................... #list
....................
.................... #use delay(clock=20000000)
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
....................
.................... #use rs232(DEBUGGER)
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=pc)
....................
....................
.................... char commandstring[30];
.................... Int i;
.................... Int buffer[];
....................
.................... #int_RDA
.................... void RDA_isr()
.................... {
.................... fgets(commandstring, pc);
0035: MOVLW 28
0036: MOVWF 04
0037: DECF 04,F
0038: INCF 04,F
0039: BTFSS 0C.5
003A: GOTO 039
003B: MOVF 1A,W
003C: MOVWF 00
003D: MOVLW 0D
003E: SUBWF 00,W
003F: BTFSS 03.2
0040: GOTO 038
0041: CLRF 00
.................... fprintf(pc,"%s\n", commandstring);
0042: MOVLW 28
0043: MOVWF 04
0044: MOVLW 00
0045: IORWF 00,W
0046: BTFSC 03.2
0047: GOTO 04E
0048: BTFSS 0C.4
0049: GOTO 048
004A: MOVF 00,W
004B: MOVWF 19
004C: INCF 04,F
004D: GOTO 044
004E: MOVLW 0A
004F: BTFSS 0C.4
0050: GOTO 04F
0051: MOVWF 19
.................... }
....................
....................
0052: BCF 0C.5
0053: BCF 0A.3
0054: BCF 0A.4
0055: GOTO 01F
.................... void main()
.................... {
0056: CLRF 04
0057: MOVLW 1F
0058: ANDWF 03,F
0059: BSF 03.5
005A: BSF 1F.0
005B: BSF 1F.1
005C: BSF 1F.2
005D: BCF 1F.3
005E: MOVLW 07
005F: BCF 03.5
0060: MOVWF 1F
0061: BSF 00.0
0062: MOVLW 81
0063: BSF 03.5
0064: MOVWF 19
0065: MOVLW 26
0066: MOVWF 18
0067: MOVLW 90
0068: BCF 03.5
0069: MOVWF 18
.................... enable_interrupts(INT_RDA); // Enable Rx interrupt
006A: BSF 03.5
006B: BSF 0C.5
.................... enable_interrupts(GLOBAL); // Enable Global interrupts
006C: MOVLW C0
006D: BCF 03.5
006E: IORWF 0B,F
....................
.................... while(1)
.................... {
....................
.................... }
006F: GOTO 06F
....................
....................
.................... }
....................
0070: SLEEP

Configuration Fuses:
Word 1: 3F7A HS NOWDT NOPUT NODEBUG NOPROTECT BROWNOUT NOLVP NOCPD NOWRT

-----------------------------------------------------------------------------
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Feb 21, 2005 1:55 am     Reply with quote

You posted the 16F877A list file which has no problems...
Please post the 18F452 list file.
Christian
Guest







PostPosted: Mon Feb 21, 2005 9:02 am     Reply with quote

sorry bout that

-----------------------------------------------------------
CCS PCH C Compiler, Version 3.211, 16465 21-Feb-05 09:01

Filename: C:\Program Files\PICC\Examples\checkin.LST

ROM used: 256 bytes (1%)
Largest free fragment is 32508
RAM used: 56 (4%) at main() level
58 (4%) worst case
Stack: 1 worst case (0 in main + 1 for interrupts)

*
0000: GOTO 00DA
*
0008: MOVWF 05
000A: MOVFF FD8,06
000E: MOVF FE9,W
0010: MOVWF 07
0012: MOVF FEA,W
0014: MOVWF 08
0016: MOVF FE1,W
0018: MOVWF 09
001A: MOVF FE2,W
001C: MOVWF 0A
001E: MOVF FD9,W
0020: MOVWF 0B
0022: MOVF FDA,W
0024: MOVWF 0C
0026: MOVF FF3,W
0028: MOVWF 14
002A: MOVF FF4,W
002C: MOVWF 15
002E: MOVF FE0,W
0030: MOVWF 0D
0032: MOVLB 0
0034: MOVF 00,W
0036: MOVWF 0F
0038: MOVF 01,W
003A: MOVWF 10
003C: MOVF 02,W
003E: MOVWF 11
0040: MOVF 03,W
0042: MOVWF 12
0044: MOVF 04,W
0046: MOVWF 13
0048: BTFSS F9D.5
004A: GOTO 0054
004E: BTFSC F9E.5
0050: GOTO 0096
0054: MOVF 0F,W
0056: MOVWF 00
0058: MOVF 10,W
005A: MOVWF 01
005C: MOVF 11,W
005E: MOVWF 02
0060: MOVF 12,W
0062: MOVWF 03
0064: MOVF 13,W
0066: MOVWF 04
0068: MOVF 0D,W
006A: MOVWF FE0
006C: BSF 0D.7
006E: MOVF 07,W
0070: MOVWF FE9
0072: MOVF 08,W
0074: MOVWF FEA
0076: MOVF 09,W
0078: MOVWF FE1
007A: MOVF 0A,W
007C: MOVWF FE2
007E: MOVF 0B,W
0080: MOVWF FD9
0082: MOVF 0C,W
0084: MOVWF FDA
0086: MOVF 14,W
0088: MOVWF FF3
008A: MOVF 15,W
008C: MOVWF FF4
008E: MOVF 05,W
0090: MOVFF 06,FD8
0094: RETFIE 0
....................
.................... #include <18F452.h>
.................... //////// Standard Header file for the PIC18F452 device ////////////////
.................... #device PIC18F452
.................... #list
....................
.................... //#include <16F877A.h>
.................... #use delay(clock=20000000)
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
....................
.................... #use rs232(DEBUGGER)
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=pc)
....................
....................
.................... char commandstring[30];
.................... Int i;
.................... Int buffer[];
....................
.................... #int_RDA
.................... void RDA_isr()
.................... {
.................... fgets(commandstring, pc);
0096: CLRF FEA
0098: MOVLW 17
009A: MOVWF FE9
009C: DECF FE9,F
009E: INCF FE9,F
00A0: BTFSS F9E.5
00A2: BRA 00A0
00A4: MOVFF FAE,FEF
00A8: MOVLW 0D
00AA: SUBWF FEF,W
00AC: BNZ 009E
00AE: CLRF FEF
.................... fprintf(pc,"%s\n", commandstring);
00B0: CLRF FEA
00B2: MOVLW 17
00B4: MOVWF FE9
00B6: MOVLW 00
00B8: IORWF FEF,W
00BA: BZ 00CC
00BC: BTFSS F9E.4
00BE: BRA 00BC
00C0: MOVFF FEF,FAD
00C4: INCF FE9,F
00C6: BTFSC FD8.2
00C8: INCF FEA,F
00CA: BRA 00B6
00CC: MOVLW 0A
00CE: BTFSS F9E.4
00D0: BRA 00CE
00D2: MOVWF FAD
.................... }
....................
....................
00D4: BCF F9E.5
00D6: GOTO 0054
.................... void main()
.................... {
00DA: CLRF FF8
00DC: BCF FD0.7
00DE: BSF 0D.7
00E0: CLRF FEA
00E2: CLRF FE9
00E4: BSF FC1.0
00E6: BSF FC1.1
00E8: BSF FC1.2
00EA: BCF FC1.3
00EC: BSF 00.0
00EE: MOVLW 81
00F0: MOVWF FAF
00F2: MOVLW 26
00F4: MOVWF FAC
00F6: MOVLW 90
00F8: MOVWF FAB
.................... enable_interrupts(INT_RDA); // Enable Rx interrupt
00FA: BSF F9D.5
.................... enable_interrupts(GLOBAL); // Enable Global interrupts
00FC: MOVLW C0
00FE: IORWF FF2,F
....................
.................... while(1)
.................... {
....................
.................... }
0100: BRA 0100
....................
....................
.................... }
....................
0102: SLEEP

Configuration Fuses:
Word 1: 2200 HS NOOSCSEN
Word 2: 0E0F BROWNOUT WDT128 NOWDT BORV20 NOPUT
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
Christian
Guest







PostPosted: Mon Feb 21, 2005 9:04 am     Reply with quote

sorry bout that
--------------------------------------------

CCS PCH C Compiler, Version 3.211, 16465 21-Feb-05 09:01

Filename: C:\Program Files\PICC\Examples\checkin.LST

ROM used: 256 bytes (1%)
Largest free fragment is 32508
RAM used: 56 (4%) at main() level
58 (4%) worst case
Stack: 1 worst case (0 in main + 1 for interrupts)

*
0000: GOTO 00DA
*
0008: MOVWF 05
000A: MOVFF FD8,06
000E: MOVF FE9,W
0010: MOVWF 07
0012: MOVF FEA,W
0014: MOVWF 08
0016: MOVF FE1,W
0018: MOVWF 09
001A: MOVF FE2,W
001C: MOVWF 0A
001E: MOVF FD9,W
0020: MOVWF 0B
0022: MOVF FDA,W
0024: MOVWF 0C
0026: MOVF FF3,W
0028: MOVWF 14
002A: MOVF FF4,W
002C: MOVWF 15
002E: MOVF FE0,W
0030: MOVWF 0D
0032: MOVLB 0
0034: MOVF 00,W
0036: MOVWF 0F
0038: MOVF 01,W
003A: MOVWF 10
003C: MOVF 02,W
003E: MOVWF 11
0040: MOVF 03,W
0042: MOVWF 12
0044: MOVF 04,W
0046: MOVWF 13
0048: BTFSS F9D.5
004A: GOTO 0054
004E: BTFSC F9E.5
0050: GOTO 0096
0054: MOVF 0F,W
0056: MOVWF 00
0058: MOVF 10,W
005A: MOVWF 01
005C: MOVF 11,W
005E: MOVWF 02
0060: MOVF 12,W
0062: MOVWF 03
0064: MOVF 13,W
0066: MOVWF 04
0068: MOVF 0D,W
006A: MOVWF FE0
006C: BSF 0D.7
006E: MOVF 07,W
0070: MOVWF FE9
0072: MOVF 08,W
0074: MOVWF FEA
0076: MOVF 09,W
0078: MOVWF FE1
007A: MOVF 0A,W
007C: MOVWF FE2
007E: MOVF 0B,W
0080: MOVWF FD9
0082: MOVF 0C,W
0084: MOVWF FDA
0086: MOVF 14,W
0088: MOVWF FF3
008A: MOVF 15,W
008C: MOVWF FF4
008E: MOVF 05,W
0090: MOVFF 06,FD8
0094: RETFIE 0
....................
.................... #include <18F452.h>
.................... //////// Standard Header file for the PIC18F452 device ////////////////
.................... #device PIC18F452
.................... #list
....................
.................... //#include <16F877A.h>
.................... #use delay(clock=20000000)
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
....................
.................... #use rs232(DEBUGGER)
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=pc)
....................
....................
.................... char commandstring[30];
.................... Int i;
.................... Int buffer[];
....................
.................... #int_RDA
.................... void RDA_isr()
.................... {
.................... fgets(commandstring, pc);
0096: CLRF FEA
0098: MOVLW 17
009A: MOVWF FE9
009C: DECF FE9,F
009E: INCF FE9,F
00A0: BTFSS F9E.5
00A2: BRA 00A0
00A4: MOVFF FAE,FEF
00A8: MOVLW 0D
00AA: SUBWF FEF,W
00AC: BNZ 009E
00AE: CLRF FEF
.................... fprintf(pc,"%s\n", commandstring);
00B0: CLRF FEA
00B2: MOVLW 17
00B4: MOVWF FE9
00B6: MOVLW 00
00B8: IORWF FEF,W
00BA: BZ 00CC
00BC: BTFSS F9E.4
00BE: BRA 00BC
00C0: MOVFF FEF,FAD
00C4: INCF FE9,F
00C6: BTFSC FD8.2
00C8: INCF FEA,F
00CA: BRA 00B6
00CC: MOVLW 0A
00CE: BTFSS F9E.4
00D0: BRA 00CE
00D2: MOVWF FAD
.................... }
....................
....................
00D4: BCF F9E.5
00D6: GOTO 0054
.................... void main()
.................... {
00DA: CLRF FF8
00DC: BCF FD0.7
00DE: BSF 0D.7
00E0: CLRF FEA
00E2: CLRF FE9
00E4: BSF FC1.0
00E6: BSF FC1.1
00E8: BSF FC1.2
00EA: BCF FC1.3
00EC: BSF 00.0
00EE: MOVLW 81
00F0: MOVWF FAF
00F2: MOVLW 26
00F4: MOVWF FAC
00F6: MOVLW 90
00F8: MOVWF FAB
.................... enable_interrupts(INT_RDA); // Enable Rx interrupt
00FA: BSF F9D.5
.................... enable_interrupts(GLOBAL); // Enable Global interrupts
00FC: MOVLW C0
00FE: IORWF FF2,F
....................
.................... while(1)
.................... {
....................
.................... }
0100: BRA 0100
....................
....................
.................... }
....................
0102: SLEEP

Configuration Fuses:
Word 1: 2200 HS NOOSCSEN
Word 2: 0E0F BROWNOUT WDT128 NOWDT BORV20 NOPUT
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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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