16f946


Closed Thread
Results 1 to 21 of 21

Thread: 16f946

  1. #1

    Default 16f946

    I have been working with a 16F946 driving an 8 digit multiplexed LCD. Attached is a "HELLO WORLD" demo program for those interested. Please note the pin connections to the LCD from the PIC are arbitrary, and I made mine for the convenience of the PCB layout guy (me!).

    Dave
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2009
    Posts
    78


    Did you find this post helpful? Yes | No

    Default lcd interrupt

    why did you PIR2.4 = 0 ?

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Page 167 of the data sheet, "Configuring the LCD Module" says to do this. Apparently, you cannot write to the LCDDATA registers at certain times. The LCD Interrupt (PIR2.4) is there to prevent attempts to do this. I haven't gotten that far into it yet.

  4. #4
    Join Date
    Jan 2009
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    i think you should use it just when you use the LCD interrupts (...should be Type B)... i will check if will work without PIR2.4 = 0

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thank you for the advice!

  6. #6


    Did you find this post helpful? Yes | No

    Default

    It seems the "HELLO WORLD" program I posted has problems. If certain characters are added to the seventh digit, the second digit becomes corrupted. The attached program is the same as the other one, with the digit "8" added after the "D" in "WORLD". You see that the "W" loses the "L" segment. I believe that this is happening because I'm trying to write characters at the wrong time. I have tried using "Type-B waveforms" and the LCD interrupt, but I don't understand how to use this interrupt. Does anyone have any ideas? Thank you.
    Attached Files Attached Files

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You should only use HIGH, LOW or TOGGLE on physical PINs.

    Using HIGH on any other register will cause it to clear a bit in another register that you didn't specify. PBP thinks it's clearing a TRIS bit, but that's only the case if a PIN is used.

    For instance, writing HIGH LCDDATA5.2 will also clear LCDDATA17.2

    HIGH LCDDATA8.3 will clear LCDDATA20.3
    ... and even worse ...
    HIGH LCDDATA12.0 will clear T1CON.0, which turns off Timer1 if running.
    All kinds of strange things can happen.

    LCDDATA12.0 = 1 would work much better.
    <br>
    DT

  8. #8


    Did you find this post helpful? Yes | No

    Thumbs down

    Thank you, Darrel! You're GREAT, as usual.

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Characters display perfectly now, thank you. Only one slight problem- when I compile with MPASM, I get the following warning: "Warning[219]c:\pbp\pbppic14.lib 905 : Invalid RAM location specified." Is this anything to be concerned with? I want to use MPASM so that I can use DT Instant Interrupts.

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jderson View Post
    Is this anything to be concerned with?
    Yes it is.

    The error is from a MOVE?CT macro. So one of the LCDDATAxx.x = 1 statements may have been edited wrong.

    If you look in the .LST file, and search for "Warning", you should see which one caused it from the line following the warning message.
    <br>
    DT

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Fixed it, thank you!

  12. #12


    Did you find this post helpful? Yes | No

    Default

    I have been trying to make an "INCLUDE" file containing all the various LCDDATA subroutines, but the compiler doesn't like it because LCDDATA is processor-specific, apparently. How is this done?

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Not sure what you mean, but ...

    The Main file that you are compiling determines the processor for all the include files too.

    If you are trying to compile the include file by itself, you probably just need to change the chip in the drop-down box in MicroCode Studio.
    <br>
    DT

  14. #14


    Did you find this post helpful? Yes | No

    Default

    Right you are, Mr. Taylor! I had the dropdown wrong (it defaults to 16f628).
    All is well once again, thank you! (I must be lacking film)

  15. #15


    Did you find this post helpful? Yes | No

    Default

    The INCLUDE file now compiles fine, but trying to compile the "Main" program causes the "Unable to open INCLUDE file NUM TEST.BAS" error. Both of the files shown below are located in c:\Program Files\Mecanique\MCS.


    This is "936 include test2" file:

    Pause 1000 ;for ICSP
    @ __config _WDT_OFF & _CP_OFF & _PWRTE_ON & _MCLRE_ON & _INTRC_OSC_NOCLKOUT

    OPTION_REG = %01000000 ;PORTB pullups enabled, no prescale
    INCLUde "num test.bas"
    ANSEL = 0 ;all pins digital
    CMCON0 = 7 ;comparators off
    ADCON0 = 0 ;ADC's off
    WDTCON = 0 ;WDT off

    TRISA = %00000000
    TRISB = %11000001 ;switches on RB6,RB7, INT on RB0
    TRISC = %00000000 ;LED on RC5, LCD bias on RC3
    TRISD = %00000000
    TRISE = %00001000 ;MCLR on RE3
    TRISF = %00000000
    TRISG = %000000

    OSCCON = %01100001 ;4 mhz. internal

    LCDPS = %00000000 ;Type-A,1/3 bias,no prescale

    LCDCON = %01010011 ;disabled,sleep disabled,VLCD disabled,LFINTOSC,
    ;1/4 mux

    ;PIR2.4 = 0 ;clear LCD interrupt
    low PORTC.5
    high PORTC.3 ;apply power to LCD bias network

    SwCount var byte




    Main:



    low PORTC.5
    low PORTC.4
    low PORTD.3

    SwCount = 0

    LCDPS = %00000000

    LCDSE0 = %10110000 ;enable appropriate segment pins
    LCDSE1 = %10010011
    LCDSE2 = %11111110
    LCDSE3 = %11111111
    LCDSE4 = %11111111
    LCDSE5 = %11

    LCDCON = %11011111 ;enable LCD module
    pause 10


    gosub Dig1_1

    goto Main




    This is "num test" file:

    Dig1_1: LCDDATA7.0 = 1
    LCDDATA4.0 = 1
    LCDDATA18.6 = 1
    RETURN

    Can someone please tell me what I'm doing wrong? Thank you.

  16. #16
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Possibly another MCS default.

    It saves new files as .PBP unless you specify .BAS
    The include statements show .BAS
    <br>
    DT

  17. #17


    Did you find this post helpful? Yes | No

    Default

    Yes, thank you! Changing the name in the main program from .bas to .pbp fixed it.

  18. #18


    Did you find this post helpful? Yes | No

    Default

    Well, I am wrong, again! The INCLUDE file compiles, but the main program doesn't display the number "1" in the first position when i use the INCLUDE file. When I move the contents of the INCLUDE file to the main program, it works. I have tried this with other combinations of files and file names, but it just won't work! Any ideas?

  19. #19
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Total guess.
    Violation of INCLUDE rule #1.

    Execution of the program must not be allowed to "Fall into" a Subroutine.

    Place a GOTO before, to a place AFTER any subroutines in the Include file.
    <br>
    DT

  20. #20


    Did you find this post helpful? Yes | No

    Default

    I guess this isn't going to work then, because there are 300 subroutines in the INCLUDE file.

  21. #21
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Oops, I guess it could have sounded that way. Didn't mean to GOTO around every subroutine individually.

    Just one GOTO at the TOP of the Include file, that jumps over all the subroutines in that file.

    Every Include file should jump over it's own subroutines.
    DT

Similar Threads

  1. 16F946 pcb footprint (64 tqfp)
    By nomad in forum Schematics
    Replies: 2
    Last Post: - 8th September 2009, 11:14
  2. Replies: 4
    Last Post: - 17th April 2009, 08:56
  3. 16F946 Instant Interrupts problem
    By jderson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th April 2009, 22:20
  4. Problem with Bank 3 in 16F946
    By karlosguay in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th September 2006, 00:19

Members who have read this thread : 1

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