Why is life (coding) so difficult !


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Why is life (coding) so difficult !

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Did you turn the analog stuff on PORTA off?
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    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:
    Code:
    '*****************************************************************************
    '*****************************************************************************
    ' 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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    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

Similar Threads

  1. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  2. need help in coding..
    By daphne8888 in forum mel PIC BASIC
    Replies: 1
    Last Post: - 19th March 2008, 07:31
  3. HPWM coding
    By civictypeR in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th January 2008, 14:54
  4. Manchester coding question
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 5th May 2007, 17:35
  5. EEPROM life expectancy?
    By muddy0409 in forum General
    Replies: 3
    Last Post: - 1st May 2007, 12:44

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts