View previous topic :: View next topic |
Author |
Message |
tonofit
Joined: 23 Jun 2005 Posts: 4
|
10 bit DAC Port definition |
Posted: Thu Jul 21, 2005 7:02 pm |
|
|
I'm working with a PIC18F722. The following I/O pins are used:
Pin H3 MSB
Pin H2
Pins J7-J0, with J0 the LSB
How do I pick a PORT Address to read/write values to the DAC?
How do I read/write the data to the DAC using a PORT HJ definition as one write of 10 bits?
I tried using the definition in the F18722.h file and making the PORT HJ use the F18722.h H3 pin since it was the MSB. That is not correct.
I guess I need to use a valid RAM address that will point to the definition of PORT. Is that right?
Code: | #define PORTHJ_BASE 31801
#define PORTHJ ((unsigned int*) PORTHJ_BASE)
typedef struct PortHJStruct
{
unsigned int HJ0 :1;
unsigned int HJ1 :1;
unsigned int HJ2 :1;
unsigned int HJ3 :1;
unsigned int HJ4 :1;
unsigned int HJ5 :1;
unsigned int HJ6 :1;
unsigned int HJ7 :1;
unsigned int HJ8 :1;
unsigned int HJ9 :1;
} PORTHJ_STRUCT;
PORTHJ_STRUCT PortHJbits;
#locate PortHJbits = PORTHJ_BASE
|
The F18722.h file has an address definition of PIN_H1 of 31801
When I try to compile the code I get the following error message
*** Error 103 "C:\PROGRA~1\PICC\drivers\string.h" Line 34(1,2): Constant out of the valid range 7C3A is out of the RAM range
*** Error 43 "C:\PROGRA~1\PICC\drivers\string.h" Line 34(6,7): Expecting a declaration |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 21, 2005 7:52 pm |
|
|
Your code is incorrect in several ways. First post the manufacturer
and part number of the DAC chip that you're using. After we look
at the data sheet, then we can decide the best way to do it. |
|
|
Guest
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jul 23, 2005 12:18 am |
|
|
Quote: | I'm working with a PIC18F722. |
I think you mean the 18F8722.
The test program shown below produces the following ASM code.
I think this is what you want.
Code: | .................... PortHJ.dac_data = 0x234;
0014: MOVLW 02
0016: MOVWF F88
0018: MOVLW 34
001A: MOVWF F87
.................... |
My version of PCH (3.188) doesn't support the 18F8722, so I compiled it
for the 18F8720, which also has ports H and J:
Code: | #include <18F8720.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
union
{
struct
{
int8 PortH;
int8 PortJ : 2;
int8 unused: 6;
}PortHJ_bits;
int16 dac_data;
}PORTHJ;
#locate PortHJ = 0xF87 // Port H (0xF87) is the base address
void main()
{
PortHJ.dac_data = 0x234;
while(1);
} |
|
|
|
|