View previous topic :: View next topic |
Author |
Message |
Philosopher
Joined: 28 Jan 2007 Posts: 6
|
DS1307 with FORCE_HW (solved) |
Posted: Sun Jan 28, 2007 8:13 am |
|
|
My I2C-communication works just fine until I try to activate the hardware with force_hw. It doesn't even get past the start()-command! Any ideas?
My setup:
CCS version 4.013
PIC16F874A at 20MHz
RTC DS1307
1k pullups on SCL- and SDA-lines (also tested with 10k)
An LCD-display to show the time
lcd_ks0066.h
Code: | #include <16F874A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES BROWNOUT //Reset when brownout detected
#use delay(clock=20000000)
//#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3)
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,force_hw)
|
lcd_ks0066.c
Code: | #include "E:\Coding\Pic\LCD KS0066\lcd_ks0066.h"
#define LCD_RS PIN_E0
#define LCD_RW PIN_E1
#define LCD_E PIN_E2
int8 lcd_read_byte()
{
int8 retval;
output_high(LCD_RW);
output_high(LCD_E);
retval = input_d();
output_low(LCD_E);
output_low(LCD_RW);
return(retval);
}
void lcd_send_byte(int8 data)
{
while(bit_test(lcd_read_byte(),7));
output_high(LCD_RS);
output_d(data);
output_high(LCD_E);
delay_cycles(1);
output_low(LCD_E);
output_low(LCD_RS);
}
void lcd_init()
{
int8 i;
output_low(LCD_RS);
output_low(LCD_RW);
output_low(LCD_E);
delay_ms(15);
for (i=0; i<3; i++)
{
output_d(0x38);
output_high(LCD_E);
delay_us(1);
output_low(LCD_E);
delay_ms(5);
}
output_d(0x06);
output_high(LCD_E);
delay_us(1);
output_low(LCD_E);
delay_us(40);
output_d(0x0E);
output_high(LCD_E);
delay_us(1);
output_low(LCD_E);
delay_us(40);
output_d(0x01);
output_high(LCD_E);
delay_us(1);
output_low(LCD_E);
delay_ms(2);
output_d(0x80);
output_high(LCD_E);
delay_us(1);
output_low(LCD_E);
delay_us(40);
}
void main()
{
int8 hh=0, mm=0, ss=0;
//-------------------------------------
// SETUP
//-------------------------------------
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//-------------------------------------
// MAIN PROGRAM
//-------------------------------------
lcd_init();
delay_ms(500);
printf(lcd_send_byte, "Time ");
i2c_start(); //THIS IS WHERE IT HANGS WITH FORCE_HW ACTIVATED
i2c_write(0xD0); //Write to DS1307
i2c_write(0x00); //Address 0
i2c_write(0x56); //Start oscillator, Seconds = 56
i2c_write(0x34); //Minutes = 34
i2c_write(0x12); //24-h, Hours = 12
i2c_write(0x01); //Day = 1
i2c_write(0x26); //Date = 26
i2c_write(0x01); //Month = 01
i2c_write(0x07); //Year = 07
i2c_write(0x10); //Square-wave out 1Hz
i2c_stop();
delay_ms(1);
i2c_start();
i2c_write(0xD0); //Write to DS1307
i2c_write(0x00); //Address 0
i2c_start();
i2c_write(0xD1); //Read from DS1307
ss = i2c_read();
mm = i2c_read();
hh = i2c_read(0);
i2c_stop();
printf(lcd_send_byte, "%x:%x:%x", hh, mm, ss);
}
|
Last edited by Philosopher on Sun Jan 28, 2007 1:41 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jan 28, 2007 9:46 am |
|
|
It might be a compiler problem. All v4.xxx versions are still to be considered beta releases and contain many bugs. That being said, you are using an old compiler version v4.023 is out already, have you tried the latest compiler version?
For production quality software I recommend you to use the last stable compiler release, v3.249. |
|
![](templates/subSilver/images/spacer.gif) |
Philosopher
Joined: 28 Jan 2007 Posts: 6
|
|
Posted: Sun Jan 28, 2007 10:03 am |
|
|
So there is nothing wrong with my code then? ![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 28, 2007 10:22 am |
|
|
Quote: | setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE); |
This is all CCS Wizard code. The setup_spi() statement shown
above in bold will shut down the SSP module. That includes
shutting down the hardware i2c. Delete that line. |
|
![](templates/subSilver/images/spacer.gif) |
Philosopher
Joined: 28 Jan 2007 Posts: 6
|
|
Posted: Sun Jan 28, 2007 10:45 am |
|
|
Ahh.. that's it!
Thank you PCM programmer! |
|
![](templates/subSilver/images/spacer.gif) |
domdom
Joined: 06 Sep 2006 Posts: 29
|
|
Posted: Fri Feb 16, 2007 6:51 am |
|
|
what type of LCD you are using? i am currently using LCD 2x16 connecting to ds1307.
can this code be used in my application?
based on the software given by philosopher, pin DB0-DB7 of LCD connecting to which I/O ports of PIC? |
|
![](templates/subSilver/images/spacer.gif) |
Philosopher
Joined: 28 Jan 2007 Posts: 6
|
|
Posted: Fri Feb 16, 2007 12:13 pm |
|
|
domdom wrote: | what type of LCD you are using? i am currently using LCD 2x16 connecting to ds1307.
can this code be used in my application?
based on the software given by philosopher, pin DB0-DB7 of LCD connecting to which I/O ports of PIC? |
I'm using a 4x16 display with a KS0066 controller chip. I believe that chip is compatible with HD44780.
You could use this code but I would recomend you to use the CCS or some other complete driver for this display instead. This is just me messing around.
If you use this code you should connect DB0-DB7 to port D. |
|
![](templates/subSilver/images/spacer.gif) |
|