|
|
View previous topic :: View next topic |
Author |
Message |
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
16F690-delay issue |
Posted: Tue Jan 22, 2008 12:00 pm |
|
|
I am trying to write a simple program to have 6 outputs that i pull low or let float high. I have started to write the program and all i am doing is toggleing one of the outputs low and float. However, when i run the program the pin is never pulled low (100K pull up to 3.3v). I am not sure what i have set up wrong that is causing the issue. Can anyone see if they can catch my mistake? I am using the internal rc at 2 mhz and would like to go lower.
Compiler version 4.062
Code: |
#include <16F690.h>
#device adc=10
//#priority ssp,rtcc,ext
#use delay(clock=2000000, RESTART_WDT)
#fuses WDT,INTRC_IO, PUT, MCLR, NOBROWNOUT, NOCPD, NOPROTECT
#use i2c(MASTER,slow,sda=PIN_C4,scl=PIN_C6)
#include <math.h>
#use fast_io(A)
#define sw_in PIN_A2 //interrupt pin
#define LED4 PIN_A4 //60% led, green
#define LED2 PIN_A5 //10-20% led, yellow
#use fast_io(B)
#define SMBD PIN_B4 //smbus data external
#define LCD_EN PIN_B5 //100% led, green
#define SMBC PIN_B6 //smbus clock external
#use fast_io(C)
//#define LCD_EN PIN_C0 //80% led, green
#define BAR1 PIN_C3
#define BAR2 PIN_C4 //smbus data, internal
#define BAR3 PIN_C5 //40% led, green
#define BAR4 PIN_C6 //smbus clock, internal
#define BAR5 PIN_C7 //10% or less led, red
//#define INTS_PER_SECOND 30
#define INTS_PER_SECOND 61 //244
#BYTE SSPCON1 = 0x14
////////////////////////////////////////////////////////////////////////////////
int address,lsb_ch_crnt,lsb_percent,msb_status;
char i,int_count,bus_free,fault,change_current,chg_term=0,set=0;
int lsb_current,msb_current,count=0,msb,lsb_volt,lsb_status;
int lsb_percent_send,lsb_temp_send,lsb_volt_send,lsb_ch_crnt_send;
int lsb_status_send,msb_status_send;
long time1,seconds,voltage,percent,status,ch_current;
long time_cnt=0,value,loop;
int32 new_val;
signed long current,temperature;
signed int i2c_temp,lsb_temp,lsb;
////////////////////////////////////////////////////////////////////////////////
#int_rtcc
void clock_isr(void)
{
if(--int_count==0) //decrement counter until 0
{
++seconds; //count up seconds
int_count=INTS_PER_SECOND; //reset counter
if (seconds>=65000)
seconds=65000;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void read_sm_percent (void)
{
i2c_start(); //read capacity
i2c_write(0x16);
i2c_write(0x0D); //relative state of charge
i2c_start();
i2c_write(0x17); //tell battery to write data
percent=i2c_read(0); //read the data
i2c_stop();
output_float(SMBC); //release data line
output_float(SMBD); //release clock line
lsb_percent=make8(percent,0);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void sm_free (void)
{
while (count<=25)
{
if ((input(SMBC))&&(input(SMBD)))
bus_free=1;
else
{
bus_free=0;
count=26;
}
delay_us(3);
count=count+1;
}
count=0;
}
////////////////////////////////////////////////////////////////////////////////
void main()
{
output_float(SMBC); //release data line
output_float(SMBD); //release clock line
output_float(LCD_EN); //turn led off
output_float(BAR1); //turn led off
output_float(BAR2); //turn led off
output_float(BAR3); //turn led off
output_float(BAR4); //turn led off
output_float(BAR5); //turn led off
setup_oscillator(osc_2mhz);
setup_adc_ports(NO_ANALOGS);
setup_wdt(WDT_ON|WDT_36MS);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
set_rtcc(0);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_a(0b00000100);
set_tris_b(0b01000000);
set_tris_c(0b00000000);
int_count=INTS_PER_SECOND; //used for timer
seconds=0; //clear out variable
time1=1; //counter for time,30 seconds
loop=0;
//percent=0;
while (TRUE)
{
output_float(SMBC); //release data line
output_float(SMBD); //release clock line
output_float(bar5);
delay_ms(33);
output_low(bar5);
delay_ms(33);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 22, 2008 12:46 pm |
|
|
Quote: |
I am toggling one of the outputs low and float. However, when I run the
program the pin is never pulled low. |
You're using Fast I/O mode. In that mode, the CCS pin i/o functions
in your program only do this:
output_float() changes the TRIS register.
output_low() changes the latch register.
So even though you change the latch register, it doesn't have any
effect on the output of the pin, because the TRIS is still set to make
the pin be an input.
You can see this in the list file. I've removed the calls to delay_ms()
for clarity:
Code: |
... while (TRUE)
... {
... output_float(SMBC); // release data line
00B8: BSF STATUS.RP0
00B9: BSF TRISB.6
... output_float(SMBD); // release clock line
00BA: BSF TRISB.4
... output_float(bar5);
00BB: BSF TRISC.7 // Set TRIS on pin C7 to input
... output_low(bar5);
00BC: BCF STATUS.RP0
00BD: BCF PORTC.7 // Set Port Register bit for pin C7 to 0.
// Note that TRIS remains set to an input.
... } |
|
|
|
|
|
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
|