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

Test GPIO 16F1823

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



Joined: 11 Dec 2011
Posts: 11
Location: Thailand

View user's profile Send private message

Test GPIO 16F1823
PostPosted: Sun Dec 11, 2011 10:05 am     Reply with quote

Hello. I'm Palm in writing codes at CCS C. PIC 16f1823, I can't control PIC16f1823 is GPIO. How to set up 16f1826 GPIO ?

Code:
  #include <16F1823.H>

    #fuses  INTRC_IO,NOWDT,NOPROTECT,MCLR
    #use    delay(clock=8M)

    #use    fast_io(A)

    #byte   PORTA   = 0x00C
    #byte   TRISA   = 0x08C
    #byte   ANSELA  = 0x18C   
    #byte   LATA    = 0x10C

    void main()
    {
     
       setup_oscillator(OSC_8MHZ|OSC_PLL_ON);
       //setup_oscillator(OSC_8MHZ | OSC_NORMAL | OSC_PLL_ON);

      ANSELA = 0x00;
      TRISA = 0b00000111;         
     
       while(TRUE)
       {
          LATA = 0b00000000;             
          delay_ms(1600);
          LATA = 0b00000111;           
          delay_ms(1600);
       }

    }


and
Code:
    #include <16F1823.H>
    #fuses  INTRC_IO,NOWDT,NOPROTECT,MCLR
    #use    delay(clock=8M)

    #use    fast_io(A)

    #byte   PORTA = 0x00C
    #byte   TRISA = 0x08C
    #byte   ANSELA  = 0x18C   
    #byte   LATA = 0x10C

    void main()
    {
     
       setup_oscillator(OSC_8MHZ|OSC_PLL_ON);
     

      set_tris_A (0x08);   

      ANSELA = 0x00;
      TRISA = 0b00000000;         
     
       while(TRUE)
       {
          output_a(0x00);     
          delay_ms(1600);
          output_a(0xff);     
          delay_ms(1600);
       }

    }

This codes don't work
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 10:49 am     Reply with quote

Seriously, just use the compiler!.
The tris register is already available for your without any register defines, so it the latch register.
Code:

#include <16F1823.H>

    #fuses  INTRC_IO,NOWDT,NOPROTECT,MCLR
    #use    delay(clock=8M)

    #use    fast_io(A)

    void main(void) {
     
      setup_oscillator(OSC_8MHZ|OSC_INTRC); //setting for 8MHz
      // - if you want the
      //PLL change the clock to match, or the timings will be wrong.
      set_adc_ports(NO_ANALOGS);
      setup_adc(ADC_OFF);

      set_tris_a(0b00000111);         
     
       while(TRUE) {
          output_a(0b00000000);             
          delay_ms(1600);
          output_a(0b00000111);           
          delay_ms(1600);
       }
    }


If you want to write assembler, use assembler, but with the compiler just use the compiler functions unless you _must_ work directly.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 1:23 pm     Reply with quote

If you can't make it work with CCS functions, then post your compiler version.
Noland



Joined: 11 Dec 2011
Posts: 11
Location: Thailand

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 8:59 pm     Reply with quote

CCS V.4.107 Now, don't work and All Pin PortA output 2.4V stable
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 1:16 am     Reply with quote

I'll test it in hardware, tomorrow morning with your version.
Noland



Joined: 11 Dec 2011
Posts: 11
Location: Thailand

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 3:31 am     Reply with quote

I test...
PIC Work, If set portA output_high or output_low
PIC don't work, If set portA output_high output_low Alternate output at portA is 2.4V stable

I think it's set x-tal Wrong.

I trial Ext and INT x-tal
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 1:32 pm     Reply with quote

Quote:
If set portA output_high output_low Alternate output at portA is 2.4V stable

How are you testing this ? Are you using an oscilloscope or a voltmeter ?

Because if you are using a voltmeter, it might be averaging the alternating
waveform into the average voltage. If goes between 0v and 4.8v,
equally for each half-cycle, the average will be 2.4 volts. Is that what
you are doing ? Are you using a voltmeter ?
Noland



Joined: 11 Dec 2011
Posts: 11
Location: Thailand

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 7:40 pm     Reply with quote

Code:
 
 output_a(0xff)
 delay_ms(2000);
 output_a(0x00)
 delay_ms(2000);


using a voltmeter Because using delay 2000 ms and test at delay 10000 ms pic don't work

the output should be 0-4.8V (0 1 0 1....)
but the output is 2.4V stable
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 8:36 pm     Reply with quote

Unfortunately I had to be out of the office almost all day (unexpectedly).
I believe I will be able to test it in hardware on Tuesday morning.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 13, 2011 1:23 pm     Reply with quote

Quote:
CCS V.4.107 Now, don't work and All Pin PortA output 2.4V stable

I looked at the .LST file and tested it in hardware.

Vs. 4.107 is just terrible for the 16F1823. It's missing half the fuses.
The .h file only lists some of the actual fuses in the PIC. The compiler
doesn't use the 2nd Config Word. It doesn't really know that it exists.

The delay_ms() routine doesn't work. It just returns quickly, maybe
doing a delay of a little more than 10 usec, when you call delay_ms(1).

There are so many things wrong that I don't want to try to make
work-arounds for all the bugs in vs. 4.107 for the 16F1823.
It would be better if you upgraded the compiler.


Quote:
the output should be 0-4.8V (0 1 0 1....)
but the output is 2.4V stable

I think the reason for this is because the waveform runs at 30 KHz or
higher (because of the bad delay_ms code), so the voltmeter just
averages it to 2.4v.

I'll do one work-around:
I've done a very quick replacement for delay_ms() which will work
for 4 MHz oscillator frequency. It uses delay_cycles(), which takes
1 usec at 4 MHz, so delay_cycles(250) gives a delay of 250 usec.
4 x 250 = 1000 usec = 1 ms delay. When the work-around function
is written as a macro (with a #define statement) then it will replace
the existing built-in function, as shown below:
Code:

#include <16F1823.H>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR
#use delay(clock=4M)

int16 cnt;               
#define delay_ms(x)    \
cnt = x;                  \
   while(cnt)             \
       {                  \
       delay_cycles(250); \
       delay_cycles(250); \
       delay_cycles(250); \
       delay_cycles(250); \
       cnt--;             \
      }                   \

//========================================
void main()
{
 
while(1)
  {
   output_a(0x00);     
   delay_ms(1600);
   output_a(0xff);     
   delay_ms(1600);
  }

}
Noland



Joined: 11 Dec 2011
Posts: 11
Location: Thailand

View user's profile Send private message

PostPosted: Tue Dec 13, 2011 10:17 pm     Reply with quote

Thank you very much. now pic work
Noland



Joined: 11 Dec 2011
Posts: 11
Location: Thailand

View user's profile Send private message

PostPosted: Fri Dec 16, 2011 2:20 am     Reply with quote

If use XTAL=8MHz PLLx4 = 32MHz I will write delay_cycles(??); ??.

Code:

#include <16F1823.H>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR
#use delay(clock=8M)

int16 cnt;               
#define delay_ms(x)    \
cnt = x;                  \
   while(cnt)             \
       {                  \
       delay_cycles(??); \
       delay_cycles(??); \
       delay_cycles(??); \
       delay_cycles(??); \
       cnt--;             \
      }                   \

//========================================
void main()
{
  setup_oscillator(OSC_8MHZ|OSC_PLL_ON);
while(1)
  {
   output_a(0x00);     
   delay_ms(1600);
   output_a(0xff);     
   delay_ms(1600);
  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 16, 2011 1:07 pm     Reply with quote

This is one way to do it. Because 32 MHz is 8x faster than 4 MHz, just
put in a for() loop that calls the same delay block for 8x.
Code:

#include <16F1823.H>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR
#use delay(clock=32M)


int8 i;
int16 cnt;               
#define delay_ms(x)            \
cnt = x;                       \
   while(cnt)                  \
       {                       \
       for(i=0; i<8; i++)      \
          {                    \
           delay_cycles(250);  \
           delay_cycles(250);  \
           delay_cycles(250);  \
           delay_cycles(250);  \
          }                    \
       cnt--;                  \
      }                   

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

while(1)
  {
   output_a(0x00);     
   delay_ms(1600);
   output_a(0xff);     
   delay_ms(1600);
  }

}



If you need any more work-arounds for this compiler version with this
PIC, you need to learn how to do it.
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