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

output_high

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



Joined: 12 Sep 2003
Posts: 10

View user's profile Send private message

output_high
PostPosted: Mon Apr 26, 2004 1:52 pm     Reply with quote

Hello,
Is there a difference between doing

output_high(PIN_A1);

and

#BYTE PORTA = 0XF80 //PORTA - PIC18F6520
#BIT PORTA1 = PORTA.1
....
PORTA1=1;

Is this effectively the same?

mle
ttelmah
Guest







Re: output_high
PostPosted: Mon Apr 26, 2004 2:35 pm     Reply with quote

mle wrote:
Hello,
Is there a difference between doing

output_high(PIN_A1);

and

#BYTE PORTA = 0XF80 //PORTA - PIC18F6520
#BIT PORTA1 = PORTA.1
....
PORTA1=1;

Is this effectively the same?

mle

Only if you have 'fast_io' selected. Otherwise, the 'output_high' function, will also clear the corresponding TRIS bit if it is set.

Best Wishes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Apr 26, 2004 2:36 pm     Reply with quote

The output-high() will deal with the TRIS register. Look at #use standard-IO(), #use fast_io() and #use fixed_io() for more information. Also compile a short test program and examine the assembly code generated. That is the acid test!
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 26, 2004 2:49 pm     Reply with quote

Two other people have posted replies while I was typing mine in.
I'll post it anyway, since it contains some additional info.
--------------

The output_high(PIN_A1) function writes to the LATA register.
Your direct i/o code writes to the PORTA register.
There is a difference between writing to these two registers.

Each of these write operations will do a Read-Modify-Write
to the entire Port A. Traditionally, this could cause a problem
because one or more bits on Port A could be temporarily
held at a different logic level than the original value that
you wrote to the Port register. This could be caused by
having a capacitor on one of the pins.

The 18F series fixes this problem by providing the Latch
registers. If you write to LATA instead of PORTA, then
the PIC will do the Read-Modify-Write operation on the
contents of the LATA register, instead of on data read
directly from the Port A pins. So if you write to the LATA
register, Port A will always be set to the value that you
intended it to be set to.

--------------------------------
There is one more difference.

In "standard i/o" mode (which is the default mode), the CCS
function, output_high(PIN_A1) will set Pin A1 to be an output
pin before it writes to the LATA register. It does this by
writing to the TRISA register.

Your direct i/o code does not set the TRISA register.
mle



Joined: 12 Sep 2003
Posts: 10

View user's profile Send private message

PostPosted: Mon Apr 26, 2004 3:01 pm     Reply with quote

So I should be doing this instead?

#BYTE LATA = 0xF89 //PORTA LATCH REGISTER
#bit LATA1 = LATA.1
...

LATA1 =1;

I'm trying to talk to a DS18s20 (1-wire temp sensor), and I can't seem to get the read/write slots working. I do get a presence pulse back from the sensor, but that's about it. I had this working fine with the pic16, but I can't get it on the PIC18. Any suggestions?

Thanks,
mle
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 26, 2004 3:20 pm     Reply with quote

Quote:
I had this working fine with the pic16, but I can't get it on the PIC18. Any suggestions?


If it doesn't work, I would check two things:

1. The Port A configuration (analog or digital).

2. The TRISA setup.

Post your setup code for each of these.
Guest








PostPosted: Tue Apr 27, 2004 7:55 am     Reply with quote

Nope it still doesn't work when I write to LATA.

Here is my portA initialization, I am reading in from RA0, and outputting on RA1

------------------------------
ADCON1 = 0x0F;

#asm
CLRF PORTA
#endasm

set_tris_a(0x15); //make DQin and input and DQout and output
-------------------------------
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 27, 2004 1:52 pm     Reply with quote

Quote:
Here is my portA initialization,
ADCON1 = 0x0F;

You're using direct i/o instead of using the built-in CCS function,
Code:
setup_port_a(NO_ANALOGS);
You didn't show the line of code where you declare the ADCON1 register.
It should look like this:
Code:
#byte ADCON1 = 0xFC1

Make sure you use #byte and not #define.

I'm suspicious of your register declarations, because
in your other code, which you posted here,
http://www.ccsinfo.com/forum/viewtopic.php?t=18984
you are using #define, and that's wrong. These lines
are from that post:
Quote:
//#define PortB 0xF81 //updated by Mike B for PIC18
#define TrisB 0xF93 //updated by Mike B for PIC18
#define TrisA 0xF92

It should be:
Code:
#byte PortB = 0xF81
#byte TrisB = 0xF93 
#byte TrisA = 0xF92

You also have this file included in your project.
Quote:
#include <18F6520definitions.h>

I wonder if that file is full of #define statements for the
register declarations, when you should be using #byte statements ?

Also, since you ported the code from a 16F series PIC to
an 18F, I wonder if all of your register addresses were changed
to the proper values for the 18F PIC ? They are all different
from the 16F series. For example, in the 18F6520, the address
of ADCON1 is 0xFC1, but for the 16F877 it is 0x9F.
Guest








PostPosted: Tue Apr 27, 2004 2:29 pm     Reply with quote

This is the 18F6520definitions.h

/******************************************/
/* */
/* This file contains all definitions for */
/* the pic18f6520 processor */
/* */
/******************************************/

/****************PIC18F6520 Processor Register Definitions*************/

#BYTE PORTA = 0XF80 //PORTA - PIC18F6520
#BYTE PORTB = 0xF81 //PORTB - PIC18F6520
#BYTE PORTC = 0xF82 //PORTC - PIC18F6520
#BYTE PORTD = 0xF83 //PORTD - PIC18F6520
#BYTE PORTE = 0xF84 //PORTE - PIC18F6520
#BYTE PORTF = 0xF85 //PORTF - PIC18F6520
#BYTE PORTG = 0xF86 //PORTG - PIC18F6520

#BYTE LATA = 0xF89 //PORTA LATCH REGISTER

#BYTE TRISA = 0XF92 //TRISA - PIC18F6520
#BYTE TRISB = 0xF93 //TRISB - PIC18F6520
#BYTE TRISC = 0xF94 //TRISC - PIC18F6520
#BYTE TRISD = 0xF95 //TRISD - PIC18F6520
#BYTE TRISE = 0xF96 //TRISE - PIC18F6520
#BYTE TRISF = 0xF97 //TRISF - PIC18F6520
#BYTE TRISG = 0xF98 //TRISG - PIC18F6520

#BYTE STATUS = 0xFD8 //STATUS register
#BYTE PIR1 = 0xF9E //Peripheral interrupt flags reg.
#BYTE PIR2 = 0xFA1 //Peripheral interrupt flags reg.
#BYTE PIR3 = 0xFA4 //Peripheral interrupt flags reg.
#BYTE PIE1 = 0xF9D //Peripheral interrupt enable reg.
#BYTE PIE2 = 0xFA0 //Peripheral interrupt enable reg.
#BYTE PIE3 = 0xFA3 //Peripheral interrupt enable reg.
#BYTE INTCON = 0xFF2 //Interrupt control register
#BYTE INTCON1 = 0xFF1
#BYTE INTCON2 = 0xFF0
#BYTE ADCON0 = 0xFC2 //A/D configure register
#BYTE ADCON1 = 0xFC1 //A/D configure register
#BYTE ADCON2 = 0xFC0 //A/D configure register
#BYTE T0CON = 0xFD5 //TIMER0 config. register
#BYTE TMR0H = 0xFD7 //TIMER0 HIGH BYTE
#BYTE TMR0L = 0xFD6 //TIMER0 LOW BYTE
#BYTE T1CON = 0xFCD //TIMER1 config. register


I'm still not getting anywhere.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 27, 2004 3:32 pm     Reply with quote

Well, I'm not sure what your problem is.
What I would do is get back to basics, and write a test
program which configures Port A for digital i/o, and then
prove that I can read an input pin, and toggle an output pin.

I would try to use only CCS functions, if possible, and not
mix CCS functions, ASM code, and direct i/o all in the
same file. I would keep everything clean and pure,
and simple.

For example, here is a test program to see if you can toggle Pin A1:
Code:
#include <18F6520.H>
#fuses XT, NOPROTECT, PUT, NOBROWNOUT, NOWDT, NOLVP
#use delay(clock=4000000)

void main()
{
setup_port_a(NO_ANALOGS);

// Look at Pin A1 with an oscilloscope to see if it is toggling.
while(1)
  {
   output_low(PIN_A1);
   delay_ms(500);
   output_high(PIN_A1);
   delay_ms(500);
  }
 
}



Here is a test program to see if you can read Pin A0:
Code:

#include <18F6520.H>
#fuses XT, NOPROTECT, PUT, NOBROWNOUT, NOWDT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, errors)

void main()
{
char c;

setup_port_a(NO_ANALOGS);

// Put a 1K pullup resistor on Pin A0.
// Then touch it with a grounded probe, and watch
// the output on a Terminal window.   When you
// touch pin A0, you should see 0's displayed.
// Normally, it will display 1's continuously.
while(1)
  {
   c = input(PIN_A0);
   if(c == 1)
      putc('1');
   else
      putc('0');   

   delay_ms(500);
  }
 
}
Guest








PostPosted: Tue Apr 27, 2004 3:48 pm     Reply with quote

Yes, I've already done this test and it works fine. I am able to read from ra0 and see it change. I don't have an oscilloscope, but I read it through a serial port on my pc.

Thanks for trying.
xinyh



Joined: 23 Mar 2004
Posts: 11

View user's profile Send private message

PostPosted: Fri Apr 30, 2004 10:03 am     Reply with quote

Hi, mle,

Did you do programming using VC++ in pc? How did you do? I only receive space in pc. Thanks!

Best Regards,
Xinyh
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