Menu

epwrite & epread problems using LCD

Help
JANIS
2017-06-21
2017-06-23
  • JANIS

    JANIS - 2017-06-21

    Hello all!
    Here is the code , that I write in parts for verification. Code is not complete. The problem is with writing in eeprom. If an instruction is written - epwrite or epread, not whichever variable is being written, then the LCD display does not want to work. The running display, which is before the main, can shows it, but after then it 1 time flashes and stands dark. I have added bookmarks to the epwrite and epread instructions. But without instructions epwrite or epread, it works. <========

    #chip 16F886, 4
       #config osc=int
    #define LCD_IO 8
    #define LCD_RS Portc.5
    #define LCD_Enable Portc.7
    #define LCD_RW Portc.6
    #define LCD_DATA_PORT PortB
    dir Portc.5 out
    dir Portc.6 out
    dir Portc.7 out
    dir PortB out
    cls
    ''#include <maths.h>
    ''+++++ DIGITAL INPUTS & OUTPUTS
    
    #define button_menu porta.1  ''  button - SETTINGS DISPLAYS SCHROLL
    dir porta.1 in
    #define button_up_down_reset porta.0 '' button + , - , reset
    dir porta.0 in
    #define RUN porta.2  ''  run signal from chains drive
    dir porta.2 in
    #define FAULT portc.2  '' fault relays
    dir portc.2 out
    #define LED portc.3   '' LED
    dir portc.3 out
    
    #define sensor_1 porta.4
    dir porta.4 in
    #define sensor_2 portc.0
    dir portc.0 in
    
    
    set LED on
     ''--------------------------------------- reklama
    locate 0,0
    print "WATCHDOG 2017 "
    wait 1 s
    'Scroll display one character right (all lines)  lcdcmd 28
    repeat 14
    lcdcmd 28
    wait 100 ms
    end repeat
    
    set LED off
    
    'Scroll display one character left (all lines)   lcdcmd 24
    ''repeat 32
    ''lcdcmd 24
    ''wait 40 ms
    ''end repeat
    
    lcdcmd 2  
     cls
    
    
    
    inittimer2 PS2_16, 0  '' (8bit timer)
    
    full=0
    sec=0
    min=0
    hours=0
    ''sec_detect=0
    
    
    inittimer1 Osc,PS1_1
    cleartimer 1
    
    
    
    sec_disp=0
    min_disp=0
    ''================
    
    pushtime_1=0
    now1=0
    prev1=0
    aa=0
    pushtime_2=0
    now2=0
    prev2=0
    bb=1
    now3=0
    prev3=0
    
    now_run=0
    prev_run=0
    now2_run=0
    prev2_run=0
    
    
    now_sens_all=0
    prev_sens_all=0
    
    now_sens1=0
    prev_sens1=0
    now_sens2=0
    prev_sens2=0
    now_sens3=0
    prev_sens3=0
    now_sens4=0
    prev_sens4=0
    now2_sens1=0
    prev2_sens1=0
    now2_sens2=0
    prev2_sens2=0
    now2_sens3=0
    prev2_sens3=0
    now2_sens4=0
    prev2_sens4=0
    bit_sens1=0
    bit_sens2=0
    bit_sens3=0
    bit_sens4=0
    bit_sens_all=0
       '' milisekundes
       milisec1=0
       milisec2=0
       milisec3=0
       milisec4=0
    diff_sens1=0
    diff_sens2=0
    diff_sens3=0
    diff_sens4=0
    
    
    
    ind_time=0
    ind_time2=0
    
    no_pulse_flt=0
    diff_flt=0
    
                                         epread 1, diff_sens1  ''  <================================
    
    main:
    starttimer 2 
    
    ''=====================================
    if !button_menu then  ''pogas nospiesanas laika ieture
    pushtime_1++
     sec_disp=0 '' nomet displeja parleksanas laiku uz 0
     min_disp=0
    else
    pushtime_1=0
    end if
    
    now1=!button_menu & pushtime_1=>50
    if now1>prev1 then
    pushtime_1=0
     aa++  '' beeper=on
     cls      
    
    end if
    prev1=now1
    ''  DISPLAY CASES
    select case aa
    
    case 0  
     MAIN_disp
    case 1''
    test_cyctime''
      case 2
    set_cyctime
    case 3
    test_difftime ''
    ''
     case 4
    ''
    set_difftime
     case 5             ''
    aa=0
      end select
    
    now_run=!RUN
    if now_run>prev_run then
    cls  
    
    sec=0
    min=0
    hours=0
    end if
    prev_run=now_run
    
    
    
    ''====================
    if !RUN then
    
    '' sensor_1 HIGH LEVEL FRONT (rising edge)
    now_sens1=!sensor_1
    if now_sens1>prev_sens1 Then
    cls
    bit_sens1=1
    milisec1=0
    diff_sens1=0
    
    end if
    prev_sens1=now_sens1
    
    'sensor_1 LOW LEVEL FRONT (falling edge)
    now2_sens1=sensor_1
    if now2_sens1>prev2_sens1 Then
    cls
    diff_sens1=milisec1
                                            epwrite 1, diff_sens1 '' <============================================
    bit_sens1=0
    milisec1=0  '' jabut pec diff_sens1=milisec1
    end if
    prev2_sens1=now2_sens1
       ''+++++++++++++++++++++++++++++++
    ' sensor_2 HIGH LEVEL FRONT (rising edge_)
    now_sens2=!sensor_2
    if now_sens2>prev_sens2 Then
    cls
    bit_sens2=1
    milisec2=0
    diff_sens2=0
    
    end if
    prev_sens2=now_sens2
    
    'sensor_2 LOW LEVEL FRONT (falling edge)
    now2_sens2=sensor_2
    if now2_sens2>prev2_sens2 Then
    cls
    diff_sens2=milisec2  ''ieraksta milisekundes mainigaja test_diff_sens2
    
    bit_sens2=0
    milisec2=0  '' jabut pec diff_sens2=milisec2
    end if
    prev2_sens2=now2_sens2
    ''+++++++++++++++++++++++++++++++++
    
    
    
    end if
    
    
    
    if min_disp=>5 Then  '' & !RUN
    cls
    aa=0
    end if
    end if
    
    ''==============================================================================
    
    wait 10 ms 
    
    goto main
    
    
    ''  CLOCK  (Timer 2)
    sub Interrupt
    TMR2IF = 0  
    full++
    if full=244 then
    sec_disp++  
    if !RUN then 
    sec++
    end if
    end if
    
    if sec_disp>59 then
    sec_disp=0
    min_disp++   
    end if
    if sec>59 then
    min++
    sec=0
    end if
    
    if min_disp>59 Then min_disp=0
    
    if min>59 then
    hours++
    min=0
    end if
    if hours>99 then hours=0
    '''===========STATUS LED (1sec tact)
    ''if full<50 then
    ''set LED on
    ''Else
    ''set LED off
    ''end if
    
    end sub
    
    
    
    
    ''' =============milisec clock  (Timer 0)
    sub milisec_timer
    if !RUN then
    milisec1++
    milisec2++
    milisec3++
    milisec4++
    end if
    
    if milisec1++ =>9999 then milisec1++=0
    if milisec2++ =>9999 then milisec2++=0
    if milisec3++ =>9999 then milisec3++=0
    if milisec4++ =>9999 then milisec4++=0
    end sub
    ''=====================
    
    
    sub MAIN_disp '' (aa=0)
    locate 0,0
    print "RUNTIME="
    if hours<10 then
    locate 0,8
    print "0"
    locate 0,9
    print hours
    Else
    locate 0,8
    print hours
    end if
    locate 0,10
    print ":"
    if min<10 Then
    locate 0,11
    print "0"
    locate 0,12
    print min
    else
    locate 0,11
     print min
    end if
    locate 0,13
    print ":"
    if sec<10 Then
    locate 0,14
    print"0"
    locate 0,15
    print sec
    Else
    locate 0,14
    print sec
    end if
    ''===========================
    
    end sub
    
    sub test_cyctime  ''  (aa=1)
    
    
    end sub
    
    
    sub  test_difftime'' (aa=3)  
    print "dif1="
    locate 0, 10
    print "2="
    locate 1, 0
    print "3="
    locate 1, 7
      print "4="
    if bit_sens1 Then
    locate 0, 5
    print milisec1 '  "RUN"
    Else
    locate 0 , 5
    print  diff_sens1
    end if
    ''=====================
    if bit_sens2 Then
    locate 0, 12
    print milisec2' "RUN"
    Else
    locate 0 , 12
    print  diff_sens2
    end if
    ''=====================
    if bit_sens3 Then
    locate 1, 2
    print milisec3' "RUN"
    Else
    locate 1 , 2
    print  diff_sens3
    end if
    ''====================
    if bit_sens4 Then
    locate 1, 2
    print milisec4' "RUN"
    Else
    locate 1 , 9
    print  diff_sens4
    end if
    
    end sub
    
     
  • William Roth

    William Roth - 2017-06-23

    @Janis

    The code above does not pass a simple syntax check so will be difficult to test. You have not declared any variables with "DIM" and your use of interrupt sub is incorrect. You are also incorrectly using bit tests and have bad code elsewhere.

    Example : This will never work: == > if milisec1++ =>9999 then milisec1++=0 '

    Please tell us what the code is supposed to do. You have 2 clock routines. Why?
    Do you need to count both seconds and mlliseconds ?

    If you are constantly interrupting the processor 244 times per second or 1000 times per second , how is the display supposed to operate?

    So explain the application. Why do you need timer0, timer1 and timer2 . What is each timer supposed to do?

     
  • Paul Haug

    Paul Haug - 2017-06-23

    My comments will only help in his future post.
    1) Structure the code with indents to clarify, paticulary loops
    2) Add lots of comments so we know what each instruction was meant to be doing.

     
  • JANIS

    JANIS - 2017-06-25

    I apologize for the late reply. I found the code problem. I will only use one timer. So far, I'm in the process of development, Iwork with code & schema & idea. After that, I'll publish both the code and the code that works.Thanks !!!!!!!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.