External clock on 16f819 problem.


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: External clock on 16f819 problem.

    OK, this is the test code. Just trying to reproduce characters.

    The IN/OUTS ADC etc are there but there's no code to run them in this version.

    The ADCON1 register is setup and the LCD displays one line but I need to study up the rest TRIS etc.

    Code:
    '****************************************************************
    '*  Name    :                                      *
    '*  Author  : Rob Lane                                          *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 13/01/2012                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Using 16f819                                      *
    '*                                                              *
    '****************************************************************
    
    
    LCD_DB4    VAR PORTB.4 
    LCD_DB5    VAR PORTB.5 
    LCD_DB6    VAR PORTB.2 
    LCD_DB7    VAR PORTB.7 
    LCD_RS     VAR PORTA.2 
    LCD_E      VAR PORTA.3 
    
    LCD_Lines  CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines) 
    LCD_DATAUS CON 50 ' Data delay time in us 
    LCD_COMMANDUS CON 2000 ' Command delay time in us
    clear
    
      ' Define ADCIN parameters
    Define	ADC_BITS	10	' Set number of bits in result
    Define	ADC_CLOCK	0	' Set clock source (Fosc/2)
    Define	ADC_SAMPLEUS	50	' Set sampling time in uS
    
    INCLUDE "LCD_AnyPin.pbp" ; *** Include MUST be AFTER LCD Pin assignments ****
    
    'setup the custom characters
    LCDOUT  $FE,$40,$01,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #0 
    LCDOUT  $FE,$48,$1F,$11,$11,$11,$11,$11,$11,$11  ' Cust Char #1  
    LCDOUT  $FE,$50,$1F,$10,$10,$10,$10,$10,$10,$1F  ' Cust Char #2  
    LCDOUT  $FE,$58,$01,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #3  
    LCDOUT  $FE,$60,$1F,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #4  
    LCDOUT  $FE,$68,$11,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #5  
    LCDOUT  $FE,$70,$1F,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #6  
    LCDOUT  $FE,$78,$1F,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #7 
    
    'setup the THICKER custom characters
    'LCDOUT  $FE,$40,$03,$03,$03,$03,$03,$03,$03,$03  ' Cust Char #0 
    'LCDOUT  $FE,$48,$1F,$1F,$1B,$1B,$1B,$1B,$1B,$1B  ' Cust Char #1  
    'LCDOUT  $FE,$50,$1F,$1F,$18,$18,$18,$18,$1F,$1F  ' Cust Char #2  
    'LCDOUT  $FE,$58,$03,$03,$03,$03,$03,$03,$1F,$1F  ' Cust Char #3  
    'LCDOUT  $FE,$60,$1F,$1F,$1B,$1B,$1B,$1B,$1F,$1F  ' Cust Char #4  
    'LCDOUT  $FE,$68,$1B,$1B,$1B,$1B,$1B,$1B,$1F,$1F  ' Cust Char #5  
    'LCDOUT  $FE,$70,$1F,$1F,$03,$03,$03,$03,$1F,$1F  ' Cust Char #6  
    'LCDOUT  $FE,$78,$1F,$1F,$03,$03,$03,$03,$03,$03  ' Cust Char #7 
    
    nPos  var byte
    nDig  var byte
    in_count  var word
    tr_out  var word
    batt_volt  VAR BYTE
    
    batt_adc var porta.0
    freq_in var portb.6
    freq_lockout var portb.3
    
    'TRISA=%10001101
    'TRISB=%01000000
    'ADCON0=%00000000
    ADCON1=%10001110   
    
    LOW PortB.0  		 ;r/w lcd line
    
    'CONFIGURE DISPLAY 
    pause 1000
    ln1 con $80
    ln2 con $C0
    CS  con 1
    pause 500
    LCDOUT $FE,1
    
    lcdout $fe, CS            ' Clear screen
    
    main:  
    	nDig=1 : npos=0 : gosub displaydigit  
    	nDig=2 : npos=1 : gosub displaydigit
        nDig=3 : npos=2 : gosub displaydigit
        nDig=4 : npos=3 : gosub displaydigit
        lcdout $FE,$80+6,"Test" 
       		
    goto main
      
    
    displaydigit:
    if ndig=0 then gosub zero
    if ndig=1 then gosub One
    if ndig=2 then gosub Two
    if ndig=3 then gosub Three
    if ndig=4 then gosub Four
    if ndig=5 then gosub Five
    if ndig=6 then gosub Six
    if ndig=7 then gosub Seven
    if ndig=8 then gosub Eight
    if ndig=9 then gosub nine
    return
       	
    Zero:
    	LCDOUT $FE,$80+nPos,1
    	LCDOUT $FE,$C0+nPos,5
    return
    
    One:
    	LCDOUT $FE,$80+nPos,0
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Two:
    	LCDOUT $FE,$80+nPos,7
    	LCDOUT $FE,$C0+nPos,2
    return
    
    Three:
    	LCDOUT $FE,$80+nPos,6
    	LCDOUT $FE,$C0+nPos,3
    return
    
    Four:
    	LCDOUT $FE,$80+nPos,5
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Five:
    	LCDOUT $FE,$80+nPos,2
    	LCDOUT $FE,$C0+nPos,3
    return
    
    Six:
    	LCDOUT $FE,$80+nPos,2
    	LCDOUT $FE,$C0+nPos,5
    return
    
    Seven:
    	LCDOUT $FE,$80+nPos,7
    	LCDOUT $FE,$C0+nPos,0
    return
    
    Eight:
    	LCDOUT $FE,$80+nPos,4
    	LCDOUT $FE,$C0+nPos,5
    return
    
    Nine:
    	LCDOUT $FE,$80+nPos,4
    	LCDOUT $FE,$C0+nPos,3
    return
    
        
    
    end

  2. #2
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: External clock on 16f819 problem.

    I've studied the datasheet time and time again, I just don't get it. I need some help to understand what I'm missing here.

    The LCD still gives one line with the code and fuses as mentioned in posts above.

    BUT I can't see what's wrong.

    I need the settings as follows:-

    PortA.0 <----- ADC in
    PortA.1 NC
    PortA.2 -------> LCD RS
    PortA.3 -------> LCD Enable
    PortA.4 NC
    PortA.5 NC
    PortA.6 NC
    PortA.7 <------ EXT Osc in (Working)

    PortB.0 RW (Low, working)
    PortB.1 NC
    PortB.2 -----> LCD D6
    PortB.3 -----> PWM Out
    PortB.4 -----> LCD D4
    PortB.5 ------> LCD D5
    PortB.6 <---- clk count in for a ref frequency to compare against external clock using tmr
    PortB.7 ------> LCD D7

    I have set ADCON1=%10001110 without this the LCD is blank.

    I've tried other settings but I'm now completely confused.

    Can someone please help.

  3. #3
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: External clock on 16f819 problem.

    I posted in the LCD_Anypin thread.

    My code with LCD_Anypin works with a 10mhz crystal oscillator but produces strange results on the LCD with EXTCLK.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: External clock on 16f819 problem.

    I have set ADCON1=%10001110 without this the LCD is blank.

    Datasheet page 83, section 11-0.

    Read settings for ADCON0 and ADCON1.

    At a glance, ADCON1 looks good, I think you need to set ADCON0 as well.

    Robert
    Last edited by Demon; - 27th January 2012 at 18:21. Reason: corrected

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