PDA

View Full Version : 16f946



jderson
- 9th March 2009, 05:35
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

bogdan
- 9th March 2009, 12:16
why did you PIR2.4 = 0 ?

jderson
- 9th March 2009, 13:12
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.

bogdan
- 10th March 2009, 00:10
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

jderson
- 10th March 2009, 03:43
Thank you for the advice!

jderson
- 15th March 2009, 03:45
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.

Darrel Taylor
- 15th March 2009, 09:56
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>

jderson
- 15th March 2009, 13:45
Thank you, Darrel! You're GREAT, as usual.

jderson
- 15th March 2009, 15:37
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.

Darrel Taylor
- 15th March 2009, 19:07
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>

jderson
- 15th March 2009, 21:15
Fixed it, thank you!

jderson
- 23rd March 2009, 23:36
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?

Darrel Taylor
- 24th March 2009, 03:00
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>

jderson
- 24th March 2009, 03:19
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)

jderson
- 24th March 2009, 14:26
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.

Darrel Taylor
- 24th March 2009, 19:12
Possibly another MCS default.

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

jderson
- 24th March 2009, 19:39
Yes, thank you! Changing the name in the main program from .bas to .pbp fixed it.

jderson
- 25th March 2009, 05:31
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?

Darrel Taylor
- 25th March 2009, 05:41
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>

jderson
- 25th March 2009, 13:54
I guess this isn't going to work then, because there are 300 subroutines in the INCLUDE file.

Darrel Taylor
- 25th March 2009, 19:44
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.