View previous topic :: View next topic |
Author |
Message |
dima2882
Joined: 13 Jul 2005 Posts: 25 Location: Maryland
|
Problem with #byte - memory mapped port won't work |
Posted: Wed Sep 14, 2005 9:21 am |
|
|
Hi all,
I am trying to read, with a small amount of code, the value of all 8 inputs to Port A of the PIC16F88. I am then trying to save that value, and send it over the serial port. I tested the SPI link, and had the PIC send sample data over it, which worked. But the #byte stuff does not... Here's the code I used:
Code: |
// Configure chip and compiler
#include "16F88.h"
#fuses INTRC_IO,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOMCLR
#use delay(clock=4000000)
#zero_ram
#byte PORTA = 5
#define F88_CS PIN_B5
void main(void)
{
// Variables
int data;
// Configure pin direction
#use fast_io(A)
#use fast_io(B)
set_tris_a(0b11111111);
set_tris_b(0b00111010);
// Setup the SPI port
setup_spi(SPI_SLAVE | SPI_H_TO_L | SPI_CLK_DIV_4);
while(1)
{
if(input(F88_CS) == 0)
{
data = PORTA;
spi_write(data);
}
else
{
delay_cycles(1);
}
}
return;
}
|
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Sep 14, 2005 9:59 am |
|
|
Are you sure its #byte problem? try
data = input_a();
and comment out use fast IO and #byte on port A
AND BTW
I wouldn't use fastIO on port B when the spi is on port B.
Let the compiler handle it. |
|
|
dima2882
Joined: 13 Jul 2005 Posts: 25 Location: Maryland
|
|
Posted: Wed Sep 14, 2005 12:20 pm |
|
|
Aah. I didn't know the compiler had a built-in input_a() function. That renders the #byte low-level stuff unecessary. Thanks for your help. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Sep 14, 2005 3:04 pm |
|
|
Keep in mind
Fast IO will save a few instructions.
Read up on exactly what it does.
I only use it when I think it will give me an advantage.
Like in a driver that can be maped to different ports with 1 line.
Code: | struct lcd_pin_map
{
int8 data;//data bus
BOOLEAN rs; //command/data_bar sometimes refered to as rs..register select
BOOLEAN rw; //read/write_bar
BOOLEAN enable;//chip enable
} lcd;
#BYTE lcd = 8 // This puts the entire structure on D and E |
|
|
|
|