PDA

View Full Version : Why is life (coding) so difficult !



malc-c
- 22nd February 2010, 14:05
In gathering examples to test some hardware and learn how to PbP works (or not in my case) I came across Mel's code for a real time clock using a DS1307.

The only changes I've made is to reflect the LCD on port B rather than port A, changed the three buttons to RA4,RA5 and RA6 (because port B is used by the LCD) and used pull up resistors as the weak pulls didn't work.

The code compiles and loads in to an 16F877A and runs fine, displaying the time on the first line, and date on the second line. However pressing RA5 (set /memorise button) results in the SET MODE being displayed with 12HR / 24HR alternating very quickly. Pressing any of the keys (RA4/5/6) has no affect and it's not possible to set any option. I have to reset the PIC to get out of the setup mode.

I've attached the file rather than post the code in the body of this thread. Hopefully someone can point me in the right direction

mackrackit
- 22nd February 2010, 14:44
Did you turn the analog stuff on PORTA off?
http://www.picbasic.co.uk/forum/showthread.php?t=561

Acetronics2
- 22nd February 2010, 15:05
Hi, malc

No, Life is not hard ...

you use chips with lots and lots of features available, and you do not "tell" it the ones you want to use ...

never forget your chip CONFIG paragraph ... it's 50% of the project good achievement ...

a small example:


'************************************************* ****************************
'************************************************* ****************************
' ThermoPID F84 test sur EasyPic5
' Thermostat PID 16F877a + DS 18B20
' 12/12/2009 : 3567 Lignes
'
'
' ATTENTION : DS1820 ... OFFSET ERROR !!!

'************************************************* ****************************
'************************************************* ****************************
'************************************************* ****************************
'************************************************* ****************************
@ ERRORLEVEL -306
@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_OFF

'************************************************* ****************************
'* LCD Defines for EasyPic5 *
'************************************************* ****************************

DEFINE LCD_DREG PORTB ' I/O port where LCD is connected
DEFINE LCD_DBIT 0 ' 0, 1, 2, 3
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4 ' Register select pin
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5 ' Enable pin
DEFINE LCD_BITS 4 ' 4-bit data bus
DEFINE LCD_LINES 2 ' LCD has 2 character lines

DEFINE OSC 8
DEFINE BUTTON_PAUSE 100


Temp_Down VAR PortA.0 'Temp down button input port
Temp_Up VAR PortA.1 'Temp up button input port
G_LED VAR PortC.0 ' Green LED output cold needed
Relay_Cold VAR PORTC.1
R_LED VAR PortC.6 ' Red LED output hot needed
Relay_hot VAR PortC.7
DQ VAR PortE.2 ' One-wire Data-Pin "DQ" on PortE.2


'************************************************* ****************************
' Variables
'************************************************* ****************************

delay VAR BYTE 'Button working variable
Loscale VAR BYTE
Hiscale VAR BYTE
Decal VAR BYTE
FAM VAR BYTE ' Sensor Family
ID VAR BYTE[7] ' Sensor ID
CRC VAR BYTE
Unit VAR BYTE ' °C or °F
DS18B20_bit VAR BYTE ' Sensor resolution

Tempeff VAR WORD
Setpoint VAR WORD
R_Temp VAR WORD ' RAW Temperature readings
TempC VAR WORD ' Temp in deg C
TempF VAR WORD
Float VAR WORD ' Holds remainder for + temp C/F display
Tempo VAR WORD

ColdStart VAR BIT
Sign VAR BIT
Busy VAR BIT
PAR VAR BIT ' Parasite Power Flag

Signe Var Word
Err Var Word
P Var Word
I Var Word

Drive Var Word
Lasterr Var Word
IntCount Var Word
Countenr Var Word
EI Var Word

Range con 100 'Intervalle de régulation en 1/10 °C
B con 50 'Centrage de régul ( +/- 50% )
Kp con 10
Ki con 2
Kd con 0
Ti con 24 '( *5 )

'************************************************* ****************************
'Configs
'************************************************* ****************************

ADCON1 = 7 ' Set PORTA and PORTE to digital
CMCON = 7 ' Comparators OFF

PORTA = %00000011 ' PortA.0 and1 are Button Controls
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0

TRISA = %00000011
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = %00000100 ' PortE.2 is DS sensor Input



Hi, Dave

+1 !!!

Alain

malc-c
- 22nd February 2010, 16:53
Did you turn the analog stuff on PORTA off?
http://www.picbasic.co.uk/forum/showthread.php?t=561

Dave

I used "ADCON1 = $0F" which should turn off A/D

Like I said it works fine and pressing the button takes it from run mode to setup mode, but then nout happens