12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Brilliant flowchart mackrackit

    Yes over the last hurdle now (I think). I've got PS_1-5 counting their own totals. Small problem in that the counts started from one all the time, then I realised that the button condition could set the count which your flow chart confirmed

    All being well the 'Mission' will be completed tomorrow.

    Watch this space...

    Dave

  2. #2
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    One last question (I think).

    The very first time the M/C is started we want 'Total' to equal zero (after all nothing's been made yet) So how do I initialize EEPROM 'Total' to zero the first time the M/C runs?. The second time it starts it reads the stored value of 'Total' and adds to that.

    The reason I'm asking this is because every time I compile and run the program, there seems to be a value already stored on EEPROM 'Total'.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Probably the best way for testing would be to write a program that writes zero to all of the EEPROM locations that you are using then re-code the chip with your main program.

    If this was for real life then a hidden reset switch or jumper could have a routine to write zeros run. Then when the jumper is removed the code jumps over the zero routine and runs the main program.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Cheers mackrackit

    So allowing for the fact that Total may contain 'random' data at start I think I've finished the 'Mission'....Hoorah!

    I've added the average parts run over the five runs on line four of the LCD. Here's the program. What do you think?:

    Code:
    ANSEL   = %00000000    'Disable analog select so ports work as digital i/o.
    CMCON0  = %00000111    'Disable analog comparators.
    TRISA   = %00100000    'Set PORTA.5 as OUTPUT.
    PORTA   = %00000000    'Set PORTA pins all low.
    TRISC   = %00000000    'Set PORTC as OUTPUT.
    PORTC   = %00000000    'Set PORTC pins all low.
    
    DEFINE LCD_DREG     PORTC    'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
    DEFINE LCD_DBIT     0
    DEFINE LCD_RSREG    PORTC
    DEFINE LCD_RSBIT    4        'PORTC.4 CONNECT TO LCD PIN4
    DEFINE LCD_EREG     PORTC
    DEFINE LCD_EBIT     5        'PORTC.5 CONNECT TO LCD PIN6
    DEFINE LCD_BITS     4
    DEFINE LCD_LINES    4
    DEFINE LCD_COMMANDUS 2000     
    DEFINE LCD_DATAUS 150
    
    DEFINE OSC 4
    
    TOTAL  VAR WORD  'STORED IN EEPROM LOCATIONS 0 AND 1
    PS_1   VAR WORD  'STORED IN EEPRON LOCATIONS 2 AND 3
    PS_2   VAR WORD  'STORED IN EEPRON LOCATIONS 4 AND 5
    PS_3   VAR WORD  'STORED IN EEPRON LOCATIONS 6 AND 7
    PS_4   VAR WORD  'STORED IN EEPRON LOCATIONS 8 AND 9
    PS_5   VAR WORD  'STORED IN EEPRON LOCATIONS 10 AND 11
    M_S    VAR BYTE  'STORED IN EEPRON LOCATIONS 12
    AV_Parts_Run var word 'STORED IN EEPRON LOCATIONS 13 AND 14
    
    clear                 'Re_set volatile memory to zero (Not EEPROM?)
    
    MAIN:
    gosub MC_S            'Set & increment M/C Starts Total subroutine
    gosub Power_up        'On Power_up GOTO READ EEPROM subroutine
    
    
    Start:
    if PORTA.5 = 0  then  count_up: 'Button pressed start counting
    IF PORTA.5 = 1  THEN     Start: 'If button not pressed loop until it is
        
    Count_up:                 'Button has been pressed
    let Total = Total + 1     'Add one to value of Total taken from EEPROM
    pause 100
    LCDOUT $FE,2,"Total=",DEC TOTAL  'Display Total on LCD
    Write 0, Total.HIGHBYTE   ' Write high byte of Total word to EEPROM
    Write 1, Total.LOWBYTE    ' Write low byte of Total word to next address
    gosub Parts_Run           'Number of parts made
    GOTO START:
    
    MC_S:                     'MC Starts subroutine
    READ 12, M_s              'Read current number of M/C Starts
    LET M_S = M_S + 1         'Increment value by one
    WRITE 12, M_S             'Save new value
    READ 12, M_s              'Read latest value
    pause 150                 'Give LCD a chance to Power_up
    LET M_S = M_S             'Set value to display
    LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
    RETURN
    
    Power_up:                 'Power_up subroutine
    Read 0, Total.HIGHBYTE	  ' Read high byte
    Read 1, Total.LOWBYTe     ' Read low byte  
    LET Total = Total         'Set Total to value set in EEPROM Memory
    pause 150                 'Give LCD a chance to Power_up
    LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
                              'Memory which has been stored since Power_down                      
    return 
    
    Parts_Run:
    SELECT CASE M_S 
       CASE 1
       if M_s = 1 then PARTS1: 
       CASE 2
       IF M_S = 2 THEN PARTS2:
       CASE 3
       IF M_S = 3 THEN PARTS3:
       CASE 4
       IF M_S = 4 THEN PARTS4:
       CASE 5
       IF M_S = 5 THEN PARTS5:
    END SELECT 
    RETURN
    
    PARTS1:
    let PS_1 = PS_1 + 1
    WRITE 2,PS_1.HIGHBYTE
    WRITE 3,PS_1.LOWBYTE
    READ  2,PS_1.HIGHBYTE
    READ  3,PS_1.LOWBYTE
    LET PS_1 = PS_1
    PAUSE 150
    LCDOUT $FE, $94,"Parts1=",DEC PS_1
    return
    
    
    PARTS2:
    LET PS_2 = PS_2 + 1
    WRITE 4,PS_2.HIGHBYTE
    WRITE 5,PS_2.LOWBYTE
    READ  4,PS_2.HIGHBYTE
    READ  5,PS_2.LOWBYTE
    LET PS_2 = PS_2
    PAUSE 150
    LCDOUT $FE, $94,"Parts2=",DEC PS_2
    return
    
    
    PARTS3:
    LET PS_3 = PS_3 + 1
    WRITE 6,PS_3.HIGHBYTE
    WRITE 7,PS_3.LOWBYTE
    READ  6,PS_3.HIGHBYTE
    READ  7,PS_3.LOWBYTE
    LET PS_3 = PS_3
    PAUSE 150
    LCDOUT $FE, $94,"Parts3=",DEC PS_3
    return
    
    
    PARTS4:
    LET PS_4 = PS_4 + 1
    WRITE 8,PS_4.HIGHBYTE
    WRITE 9,PS_4.LOWBYTE
    READ  8,PS_4.HIGHBYTE
    READ  9,PS_4.LOWBYTE
    LET PS_4 = PS_4
    PAUSE 150
    LCDOUT $FE, $94,"Parts4=",DEC PS_4
    return
    
    
    PARTS5:
    LET PS_5 = PS_5 + 1
    WRITE 10,PS_5.HIGHBYTE
    WRITE 11,PS_5.LOWBYTE
    READ  10,PS_5.HIGHBYTE
    READ  11,PS_5.LOWBYTE
    LET PS_5 = PS_5
    PAUSE 150
    LCDOUT $FE, $94,"Parts5=",DEC PS_5
    
    READ  2,PS_1.HIGHBYTE
    READ  3,PS_1.LOWBYTE
    LET PS_1 = PS_1
    READ  4,PS_2.HIGHBYTE
    READ  5,PS_2.LOWBYTE
    LET PS_2 = PS_2
    READ  6,PS_3.HIGHBYTE
    READ  7,PS_3.LOWBYTE
    LET PS_3 = PS_3
    READ  8,PS_4.HIGHBYTE
    READ  9,PS_4.LOWBYTE
    LET PS_4 = PS_4
    READ  10,PS_5.HIGHBYTE
    READ  11,PS_5.LOWBYTE
    LET PS_5 = PS_5
    
    let AV_Parts_Run = (PS_1 + PS_2 + PS_3 + PS_4 + PS_5)/5
    write 13,AV_parts_Run.HIGHBYTE
    WRITE 14,AV_Parts_Run.LOWBYTE
    READ  13,AV_parts_Run.HIGHBYTE
    READ  14,AV_Parts_Run.LOWBYTE
    let AV_Parts_Run = AV_Parts_Run
    PAUSE 150
    LCDOUT $FE, $D4,"AV_Parts_Run =",DEC AV_Parts_Run
    end
    Last edited by LEDave; - 11th May 2010 at 17:52.

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


    Did you find this post helpful? Yes | No

    Default

    I am on the road again with a small display but what I can see looks good!

    I take you have ran it a few times and it is working as expected?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    I take you have ran it a few times and it is working as expected?
    I've got a bug (it maybe a small infestation!)...(I could have swore it worked earlier!)

    I spoke too soon, 'Mission' incomplete. I'll try and debug it later tonight.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    I added a couple things, messes up your averaging part (never gets there now) but maybe this will help.
    Other than that it is looking good!!!!
    Code:
    MC_S:                     'MC Starts subroutine
    READ 12, M_s              'Read current number of M/C Starts
    LET M_S = M_S + 1         'Increment value by one
    '#######
    IF M_S > 5 THEN
    M_S = 0
    ENDIF
    '#######
    WRITE 12, M_S             'Save new value
    READ 12, M_s              'Read latest value
    pause 150                 'Give LCD a chance to Power_up
    LET M_S = M_S             'Set value to display
    LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
    RETURN
    
    Power_up:                 'Power_up subroutine
    Read 0, Total.HIGHBYTE      ' Read high byte
    Read 1, Total.LOWBYTe     ' Read low byte  
    '#######
    IF TOTAL > 5000 THEN
    TOTAL = 0
    ENDIF
    '#######
    LET Total = Total         'Set Total to value set in EEPROM Memory
    pause 150                 'Give LCD a chance to Power_up
    LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
                              'Memory which has been stored since Power_down                      
    return
    Dave
    Always wear safety glasses while programming.

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