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

help rs 232

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







help rs 232
PostPosted: Tue Feb 17, 2009 11:36 am     Reply with quote

i have problem

program

Code:
#include <18F452.h>
#device *=16
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES PROTECT                  //Code protected from reads
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#include <stdio.h>

#use delay(clock=20000000)
//#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
INT16 B;
#byte leds=0x09
#bit led_1=leds.0
#bit led_2=leds.1
#bit led_3=leds.2

#byte RS_485=0x07
#bit DE=RS_485.2
#bit HF=RS_485.5

#DEFINE ON 1;
#DEFINE OFF 0;

#INT_RDA
VOID PRIEM()
{
   b=fgetc();
   led_1=1;
      clear_interrupt(INT_RDA);
}


void main()
{
char c[]="cfgjgh";
set_tris_E(0x00);
set_tris_C(0x9B);

HF=Off;
DE=On;

led_1=0;
led_2=1;
led_3=1;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

//,INVERT,FORCE_SW

   WHILE(1)
   {
   DELAY_MS(100);
   putchar('1'); DELAY_MS(100);
      putchar('2');   DELAY_MS(100);
         putc('3');   DELAY_MS(100);
            putc('4');   DELAY_MS(100);
               putc(5);   DELAY_MS(100);
                  putc(6);   DELAY_MS(100);
                     putc(7);   DELAY_MS(100);
                        putc(8);   DELAY_MS(100);
                        putc(0);   DELAY_MS(100);
                        putc(0xFE);   DELAY_MS(100);
      DELAY_MS(100);
      putchar(c[1]);
        DELAY_MS(100);

   }
}

and data on terminal
Code:
C3 FC;HEX;
C4 FC;HEX;
C7 FC;HEX;
C8 FC;HEX;
0B FC;HEX;
0C FC;HEX;
0F FC;HEX;
30 FC;HEX;
00;HEX;
FC;HEX;
8C FF;HEX;

I am VERY bad speak english(I am from ukraine). Pplease help me with program.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 17, 2009 12:52 pm     Reply with quote

Quote:

#device *=16

This line is not needed. The 18F compiler always uses 16-bit pointers.

Quote:

#byte leds=0x09
#bit led_1=leds.0
#bit led_2=leds.1
#bit led_3=leds.2

#byte RS_485=0x07
#bit DE=RS_485.2
#bit HF=RS_485.5

The addresses used for 'leds' and 'RS_485' are wrong. Thoses addresses
are for the 16F PICs (such as 16F877). To find the correct addresses
for Port E and Port C in the 18F452, look in the 18F452 data sheet, in
the following section:
Quote:
TABLE 4-1: SPECIAL FUNCTION REGISTER MAP



Quote:
#INT_RDA
VOID PRIEM()
{
b=fgetc();
led_1=1;
clear_interrupt(INT_RDA);
}

The line in bold is not necessary. The CCS compiler automatically puts
in code at the end of the interrupt routine to clear the RDA interrupt.
Guest








PostPosted: Tue Feb 17, 2009 12:59 pm     Reply with quote

PCM programmer wrote:
Quote:

#device *=16

This line is not needed. The 18F compiler always uses 16-bit pointers.

Quote:

#byte leds=0x09
#bit led_1=leds.0
#bit led_2=leds.1
#bit led_3=leds.2

#byte RS_485=0x07
#bit DE=RS_485.2
#bit HF=RS_485.5

The addresses used for 'leds' and 'RS_485' are wrong. Thoses addresses
are for the 16F PICs (such as 16F877). To find the correct addresses
for Port E and Port C in the 18F452, look in the 18F452 data sheet, in
the following section:
Quote:
TABLE 4-1: SPECIAL FUNCTION REGISTER MAP



Quote:
#INT_RDA
VOID PRIEM()
{
b=fgetc();
led_1=1;
clear_interrupt(INT_RDA);
}

The line in bold is not necessary. The CCS compiler automatically puts
in code at the end of the interrupt routine to clear the RDA interrupt.

SORRY I HAVE PIC16F877A.I DONT UNERSTEND WHY DATA IN TERMINAL
NOT == DATA IN PIC
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 17, 2009 1:02 pm     Reply with quote

Then don't post stuff like this:
Quote:
#include <18F452.h>

How can I believe your code is accurate ?
Guest








PostPosted: Tue Feb 17, 2009 1:21 pm     Reply with quote

PCM programmer wrote:
Then don't post stuff like this:
Quote:
#include <18F452.h>

How can I believe your code is accurate ?


Code:
#include <16F877A.h>
#device *=16
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES PROTECT                  //Code protected from reads
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#include <stdio.h>

#use delay(clock=20000000)
//#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
INT16 B;
#byte leds=0x09
#bit led_1=leds.0
#bit led_2=leds.1
#bit led_3=leds.2

#byte RS_485=0x07
#bit DE=RS_485.2
#bit HF=RS_485.5

#DEFINE ON 1;
#DEFINE OFF 0;

#INT_RDA
VOID PRIEM()
{
   b=fgetc();
   led_1=1;
      clear_interrupt(INT_RDA);
}


void main()
{
char c[]="cfgjgh";
set_tris_E(0x00);
set_tris_C(0x9B);

HF=Off;
DE=On;

led_1=0;
led_2=1;
led_3=1;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);



   WHILE(1)
   {
   DELAY_MS(100);
   putchar('1'); DELAY_MS(100);
      putchar('2');   DELAY_MS(100);
         putc('3');   DELAY_MS(100);
            putc('4');   DELAY_MS(100);
               putc(5);   DELAY_MS(100);
                  putc(6);   DELAY_MS(100);
                     putc(7);   DELAY_MS(100);
                        putc(8);   DELAY_MS(100);
                        putc(0);   DELAY_MS(100);
                        putc(0xFE);   DELAY_MS(100);
      DELAY_MS(100);
      putchar(c[1]);
        DELAY_MS(100);

   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 17, 2009 4:49 pm     Reply with quote

Your program is too complicated. Make a very simple program to test
the RS-485. Let the compiler set the TRIS. It will do it automatically
if you use CCS functions. Example:
Code:
#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define DE  PIN_C2
#define HF  PIN_C5

//======================================
void main()
{
output_low(HF);
output_high(DE);

printf("Hello World\n\r");

while(1);
}



Also, CCS has a feature in the #use rs232() statement, where you can
specify the Enable pin for the RS-485 driver chip. Example:
Code:
#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, ENABLE=PIN_C2)

//======================================
void main()
{

printf("Hello World\n\r");

while(1);
}

I don't know what the "HF" pin is doing in your program, so I left out the
code for it.
Guest








PostPosted: Wed Feb 18, 2009 12:40 am     Reply with quote

PCM programmer wrote:
Your program is too complicated. Make a very simple program to test
the RS-485. Let the compiler set the TRIS. It will do it automatically
if you use CCS functions. Example:
Code:
#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define DE  PIN_C2
#define HF  PIN_C5

//======================================
void main()
{
output_low(HF);
output_high(DE);

printf("Hello World\n\r");

while(1);
}



Also, CCS has a feature in the #use rs232() statement, where you can
specify the Enable pin for the RS-485 driver chip. Example:
Code:
#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, ENABLE=PIN_C2)

//======================================
void main()
{

printf("Hello World\n\r");

while(1);
}

I don't know what the "HF" pin is doing in your program, so I left out the
code for it.

I HAVE MAX3089. I DO ALWAYS IN AND FULL DUPLEX.
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