PDA

View Full Version : PIC18F4620 Troubles



CluckShot
- 15th May 2007, 01:22
I am taking the standard program to demo the PIC16F877A as a clock and starting to branch out leaning as I go. Sorry if I am just leaning but I could really use some help The problem obviously is in configuration of the ports and interrupts.

Since the PIC18F4620 has several timers rather than the one of the PIC16F877A I assume that some sort of configuration for setting the interrupts on should be done differently but I am not entirely able to get this down. Chalk it up to learning but I need some help on this one.

I will include my defines and the settings and what should be printing out. The rest of the program really is quite generic.

Defines --
Define LCD_DREG PORTD ' Define LCD connections
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
ADCON1 = 7 ' PORTA and E digital
Low PORTE.2 ' LCD R/W low = write

' Set TMR0 to interrupt every 16.384 milliseconds
T0CON.7 = 1 ' Set Timer0 on!
T0Con.6 = 0 ' Set as a 16 bit timer/counter
T0Con.5 = 0 ' Set the internal clock active
T0Con.4 = 0 ' Set Source edge bit = low to high on T0CLKI pin
T0Con.3 = 1 ' Bypass the prescaler (Revisit this one!)
T0Con.2 = 0 ' Prescaler settings
T0Con.1 = 0
T0Con.0 = 0
TRISD = %11111111

'PSPCON = 0
'OPTION_REG = $88 ' Set TMR0 configuration and enable PORTB pullups
Enable interrupt ' Enable TMR0 interrupts
'INTCON =
On Interrupt Goto tickint

-===

If you go to the standard clockx example on the melabs site you get the rest of the code, I really don't expect it to be of much interest.


My issue is that the system has an led that flashes with each interrupt and it appears to be working just fine. The problem is that the LCDOUT writing per this program is not working. It works just fine with the PIC16F877A chip.

Help Please

mister_e
- 15th May 2007, 02:12
Hi and welcome on the forum.

Try to change ADCON1=7 to ADCON1=$0F.

CluckShot
- 15th May 2007, 12:01
First Thanks!

Next I will try your solution and report the results and report if there are any problems.

Finally: Please tell me why this should work. In trying to read all the fun stuff down in the chip technical papers I must be missing something and I definitely want to be more astute as to why as well as how.

Thanks again
Paul

ra68gi
- 15th May 2007, 13:05
Defines --
Define LCD_DREG PORTD ' Define LCD connections
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
ADCON1 = 7 ' PORTA and E digital
Low PORTE.2 ' LCD R/W low = write


Help Please

Try adding "Define LCD_BITS 4 " to your defines.

Regards
Raghunathan.

Pic_User
- 15th May 2007, 15:42
First Thanks!

Next I will try your solution and report the results and report if there are any problems.

Finally: Please tell me why this should work. In trying to read all the fun stuff down in the chip technical papers I must be missing something and I definitely want to be more astute as to why as well as how.

Thanks again
Paul

Hi Paul,
To find out more about mister_e’s helpful answer, you can use, the forum search engine, to look for:
ADCON1=$0F

The data sheets can be searched the same way.

-Adam-

mister_e
- 15th May 2007, 15:56
FYI, this DEFINE is the default one, if you don't write it yourself, PBP will do it for you in background.

Let's see what happen in the .LST file, i compile those lines...


Define LCD_DREG PORTD ' Define LCD connections
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1

LCDOUT "Hello"

Now, i open the .LST file, scroll to the end... and


LCD_BITS 00000004
LCD_COMMANDUS 000007D0
LCD_DATAUS 00000032
LCD_DBIT 4
LCD_DREG PORTD
LCD_EBIT 1
LCD_EREG PORTE
LCD_LINES 00000002
LCD_RSBIT 0
LCD_RSREG PORTE
LCD_RWBIT 00000000
LCD_RWREG 00000009

everything is there. Now what happen, if i don't use any DEFINE


lcdout "Hello"


.LST


LCD_BITS 00000004
LCD_COMMANDUS 000007D0
LCD_DATAUS 00000032
LCD_DBIT 00000000
LCD_DREG 00000005
LCD_EBIT 00000003
LCD_EREG 00000006
LCD_LINES 00000002
LCD_RSBIT 00000004
LCD_RSREG 00000005
LCD_RWBIT 00000004
LCD_RWREG 00000005

Interesting eh! But i agree, it's always nice to have ALL DEFINE in your code, so if one day you decide to change them, it's just easy. PICMultiCalc also generate those.. kinda lazy stuff... and some day i am :D

---------------------------------------


Finally: Please tell me why this should work. In trying to read all the fun stuff down in the chip technical papers I must be missing something and I definitely want to be more astute as to why as well as how.

Well, why ADCON1 would have to work? Where did you get this value ? ;)

Let's see a datasheet snip...
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1634&stc=1&d=1179240738">

ADCON1=7 set PCFG3:PCFG0 to 0111.. right? If so, what happen to AN0,1,2,3,4,5,6,7 ?

ADCON1=$0F set PCFG3:PCFG0 to 1111.. right? If so, what happen to AN0,1,2,3,4,5,6,7,8,9,10,11,12 ?

I think it's the explanation :-)

EDIT: Sorry PicUser.. we write at the same time !

CluckShot
- 16th May 2007, 03:02
You confirmed my research and it is always nice to have someone back up your thinking. It either means that the both of you are lost ... (not in this case) or that you actually understand what the other person is saying. (something nice)

In any case thanks so much and I am sure I will be back and hopefully I will have nice helpful things for others as well.

Paul