Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 23rd April 2008, 02:52 AM   (permalink)
Default

Just to be on the safe side, change these
Code:
#define	DI		PORTAbits.RA2
#define RW		PORTAbits.RA1
#define E		PORTAbits.RA0
#define CS1		PORTAbits.RA3
#define CS2		PORTAbits.RA4
#define RST		PORTAbits.RA5
to this
Code:
#define	DI		LATAbits.RA2
#define RW		LATAbits.RA1
#define E		LATAbits.RA0
#define CS1		LATAbits.RA3
#define CS2		LATAbits.RA4
#define RST		LATAbits.RA5
And, like Pommie says, check that any ports you're using with A/D on them are set for all digital. Default is analog. Weird, bad things will happen (it won't work).
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Old 23rd April 2008, 03:03 AM   (permalink)
Default

Quote:
Originally Posted by Pommie

(ADCON1=0x06 for the 18F452)
So that'll turn all the ports digital or only some?
desaila is offline   Reply With Quote
Old 23rd April 2008, 03:11 AM   (permalink)
Default

Quote:
Originally Posted by desaila
So that'll turn all the ports digital or only some?
Look it up in the datasheet. If you're programming PICs, you should always have a datasheet handy. If you don't, you're just guessing and will never get things working.

Sorry if I sound grumpy, but that was a really dumbass question.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Old 23rd April 2008, 03:13 AM   (permalink)
Default

haha, fair enough.
desaila is offline   Reply With Quote
Old 23rd April 2008, 03:27 AM   (permalink)
Default

Quote:
Originally Posted by desaila
haha, fair enough.
I'm seeing ADCON1 = 0x07 to configure portA for digital inputs, but there's nothing under the PORTB configuration with regards to digital or analog inputs.

However, it says on a power on reset "these ports are configured as digital inputs." Then, I guess I see that there are no AD's associated with PORTB in the final summary of regs at the bottom of PORTB's section. So, ADCON1 = 0x07 then.
desaila is offline   Reply With Quote
Old 23rd April 2008, 03:33 AM   (permalink)
Default

Quote:
Originally Posted by desaila
I'm seeing ADCON1 = 0x07 to configure portA for digital inputs, but there's nothing under the PORTB configuration with regards to digital or analog inputs.

However, it says on a power on reset "these ports are configured as digital inputs." Then, I guess I see that there are no AD's associated with PORTB in the final summary of regs at the bottom of PORTB's section. So, ADCON1 = 0x07 then.
Sounds right. I'm on my "accounting" computer, so I don't have access to datasheets right now. Must get some invoices out so I can eat next month.

EDIT: Just looked. What you want is on page 182 of the datasheet. 0x06 will work, but so will 0x07 as the 0-bit is a don't-care in this case.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 23rd April 2008 at 04:21 AM.
futz is offline   Reply With Quote
Old 23rd April 2008, 05:35 PM   (permalink)
Default

Quote:
Originally Posted by futz
Well, right off the bat I have to say this #pragma
Code:
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF
is almost certainly wrong for an 18F. 18Fs have seven config words, whereas the 16Fs I wrote for only have one. Your compiler MUST have been at least warning you. It should have given you major errors.

Here's a set of typical BoostC pragmas for an 18F452
Code:
#pragma DATA    _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
#pragma DATA    _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L
#pragma DATA    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
#pragma DATA    _CONFIG3H, _CCP2MX_ON_3H
#pragma DATA    _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
#pragma DATA    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
#pragma DATA    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
#pragma DATA    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
#pragma DATA    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
#pragma DATA    _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
#pragma DATA    _CONFIG7H, _EBTRB_OFF_7H
And here's a minimum one that I use mostly:
Code:
#pragma	CLOCK_FREQ	32000000
#pragma DATA    _CONFIG1H, _OSC_INTIO67_1H
#pragma DATA    _CONFIG2H, _WDT_OFF_2H
#pragma DATA    _CONFIG3H, _MCLRE_ON_3H
#pragma DATA    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
That CLOCK_FREQ line is so the delay lib calculates delays correctly.

All the above assumes BoostC. Your compiler may have different syntax.
I changed my inputs to the Latching system as recommended, threw in ADCON1 = 0x07 immediately after variable declaration, and tried looking up these various pragmas in the MPLAB C18 user guides I have in this lab, and couldn't find any of the ones you used, or their explanations. I tried searching through the data sheet as well. Where can I find configuration info? I tried google'ing a few of them, but nothing terribly useful came up, not that I could see anyway.

(no change in status of lcd).
desaila is offline   Reply With Quote
Old 23rd April 2008, 10:26 PM   (permalink)
Default

Quote:
Originally Posted by desaila
and tried looking up these various pragmas in the MPLAB C18 user guides I have in this lab, and couldn't find any of the ones you used, or their explanations.
Ok, you can't use the same pragmas as BoostC. C18 has a sort of simplified version of the same thing though.

Quote:
I tried searching through the data sheet as well.
The datasheet has good info on the configs, but not compiler specific info.

Quote:
Where can I find configuration info?
Relax. Here it comes.

In your MCC18 dir you'll find an mpasm dir. In there you'll find a file called P18F452.INC. Near the bottom of that you'll find this list:
Code:
;   Oscillator Selection:
;     OSC = LP             LP
;     OSC = XT             XT
;     OSC = HS             HS
;     OSC = RC             RC
;     OSC = EC             EC-OSC2 as Clock Out
;     OSC = ECIO           EC-OSC2 as RA6
;     OSC = HSPLL          HS-PLL Enabled
;     OSC = RCIO           RC-OSC2 as RA6
;
;   Osc. Switch Enable:
;     OSCS = ON            Enabled
;     OSCS = OFF           Disabled
;
;   Power-up Timer:
;     PWRT = ON            Enabled
;     PWRT = OFF           Disabled
;
;   Brown-out Reset:
;     BOR = OFF            Disabled
;     BOR = ON             Enabled
;
;   Brown-out Voltage:
;     BORV = 45            4.5V
;     BORV = 42            4.2V
;     BORV = 27            2.7V
;     BORV = 25            2.5V
;
;   Watchdog Timer:
;     WDT = OFF            Disabled
;     WDT = ON             Enabled
;
;   Watchdog Postscaler:
;     WDTPS = 1            1:1
;     WDTPS = 2            1:2
;     WDTPS = 4            1:4
;     WDTPS = 8            1:8
;     WDTPS = 16           1:16
;     WDTPS = 32           1:32
;     WDTPS = 64           1:64
;     WDTPS = 128          1:128
;
;   CCP2 MUX:
;     CCP2MUX = OFF        Disable (RB3)
;     CCP2MUX = ON         Enable (RC1)
;
;   Stack Overflow Reset:
;     STVR = OFF           Disabled
;     STVR = ON            Enabled
;
;   Low Voltage ICSP:
;     LVP = OFF            Disabled
;     LVP = ON             Enabled
;
;   Background Debugger Enable:
;     DEBUG = ON           Enabled
;     DEBUG = OFF          Disabled
;
;   Code Protection Block 0:
;     CP0 = ON             Enabled
;     CP0 = OFF            Disabled
;
;   Code Protection Block 1:
;     CP1 = ON             Enabled
;     CP1 = OFF            Disabled
;
;   Code Protection Block 2:
;     CP2 = ON             Enabled
;     CP2 = OFF            Disabled
;
;   Code Protection Block 3:
;     CP3 = ON             Enabled
;     CP3 = OFF            Disabled
;
;   Boot Block Code Protection:
;     CPB = ON             Enabled
;     CPB = OFF            Disabled
;
;   Data EEPROM Code Protection:
;     CPD = ON             Enabled
;     CPD = OFF            Disabled
;
;   Write Protection Block 0:
;     WRT0 = ON            Enabled
;     WRT0 = OFF           Disabled
;
;   Write Protection Block 1:
;     WRT1 = ON            Enabled
;     WRT1 = OFF           Disabled
;
;   Write Protection Block 2:
;     WRT2 = ON            Enabled
;     WRT2 = OFF           Disabled
;
;   Write Protection Block 3:
;     WRT3 = ON            Enabled
;     WRT3 = OFF           Disabled
;
;   Boot Block Write Protection:
;     WRTB = ON            Enabled
;     WRTB = OFF           Disabled
;
;   Configuration Register Write Protection:
;     WRTC = ON            Enabled
;     WRTC = OFF           Disabled
;
;   Data EEPROM Write Protection:
;     WRTD = ON            Enabled
;     WRTD = OFF           Disabled
;
;   Table Read Protection Block 0:
;     EBTR0 = ON           Enabled
;     EBTR0 = OFF          Disabled
;
;   Table Read Protection Block 1:
;     EBTR1 = ON           Enabled
;     EBTR1 = OFF          Disabled
;
;   Table Read Protection Block 2:
;     EBTR2 = ON           Enabled
;     EBTR2 = OFF          Disabled
;
;   Table Read Protection Block 3:
;     EBTR3 = ON           Enabled
;     EBTR3 = OFF          Disabled
;
;   Boot Block Table Read Protection:
;     EBTRB = ON           Enabled
;     EBTRB = OFF          Disabled
Take the ones you need and put them after #pragma config. This small set of pragma's should get you going. You'll have to change the OSC line to suit your oscillator. I assumed you'd be using a HS (high speed) crystal. Change that to suit how you're doing it. To find which one to use, refer to Page 17 in the datasheet:
Code:
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
EDIT: I downloaded C18 and tested a bit. On my 18F4620, using internal oscillator, I'm using this #pragma for a simple blinky program:
Code:
#include <p18cxxx.h>
#include <delays.h>

#pragma config OSC = INTIO67, WDT = OFF, LVP = OFF

void main(void)
{
	TRISD = 0;
	while(1){
		LATDbits.LATD1 = 1;
		Delay100TCYx(100);
		LATDbits.LATD1 = 0;
		Delay100TCYx(100);
	}
}
As you can see, you can put them all on one line with commas between them if you prefer it over one-per-line.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 24th April 2008 at 06:20 AM.
futz is offline   Reply With Quote
Old 23rd April 2008, 10:45 PM   (permalink)
Default

Thanks a bunch! I'm not going to be in the lab again tonight, but I'm going to head over there first thing in the morning to give this a go.
desaila is offline   Reply With Quote
Old 24th April 2008, 04:21 PM   (permalink)
Default

heh, so I just changed some of the init things to test out, and i was playing with the contrast potentiometer i have setup, and the thing started smoking...(not the pot, but the lcd itself.) I cut the power as quick as I could and turned it over to investigate and nothing looks damaged.

so now i'm petrified that it burnt out. Is there a way to verify that the lcd might actually be working despite nothing showing up on it?

EDIT: Also, in case the thing is still working... I'm using a 20 mhz oscillator, so should I be using a Delay1KTCYx() instead of the Nops?

Or do you have like simplified code that just puts out like 1 letter to the device or something, so I can just try adn get the timing down on this thing and verify if it's really dead or not? (sorta like your blinky program)?

Last edited by desaila; 24th April 2008 at 04:57 PM.
desaila is offline   Reply With Quote
Old 24th April 2008, 05:10 PM   (permalink)
Default

Smoke = bad. LCD displays are very sensitive to incorrectly applied power and such. I've killed a couple in my day from just a brief power reversal.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 24th April 2008, 05:27 PM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
Smoke = bad. LCD displays are very sensitive to incorrectly applied power and such. I've killed a couple in my day from just a brief power reversal.

Aye, tbh I think it has something to do wtih the company. The first LCD I got from them smoked the first time I wired it up. I called them, told them what happened and that I tested all the voltages prior to wiring it up, and after the failure and they wre all within operating range.

They sent me a new one for free, the second one they sent me is the one I have now. I had my professor help me wire it, test all the voltages before we wired it up, etc. So I really don't think it's my fault, maybe it was =/
desaila is offline   Reply With Quote
Old 24th April 2008, 11:52 PM   (permalink)
Default

Quote:
Originally Posted by desaila
so now i'm petrified that it burnt out. Is there a way to verify that the lcd might actually be working despite nothing showing up on it?
You let the magic smoke out. Pretty unlikely that it still works, but try it anyway. You can't hurt it anymore than you already have. If you've smoked two in a row it's your faulty wiring, not the display, that's at fault.

Quote:
I had my professor help me wire it, test all the voltages before we wired it up, etc.
Perhaps your professor has misunderstood something on the datasheet, or made a mistake. Have a look at my schematic and confirm your wiring again.

Quote:
EDIT: Also, in case the thing is still working... I'm using a 20 mhz oscillator, so should I be using a Delay1KTCYx() instead of the Nops?
No. The nops are fine. It's happy at 20MHz with that code.

Quote:
Or do you have like simplified code that just puts out like 1 letter to the device or something, so I can just try adn get the timing down on this thing and verify if it's really dead or not? (sorta like your blinky program)?
That's as simple as it gets. This isn't a text LCD. Any text it puts on screen gets put there the hard way, by your code. Make your own font and find a way to display it as a bitmap.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 24th April 2008 at 11:57 PM.
futz is offline   Reply With Quote
Old 25th April 2008, 12:06 AM   (permalink)
Default

I understand the nature of this lcd not being text driven and having to get your own character libraries, etc

Also, I have it wired in a very similar way. Just a potentiometer instead of a 10k. It wasn't just my professor either, I had the TA double check it prior to firing it up for the first time. It was fine for ~2 weeks and them smoked. Is that something that can be expected?
desaila is offline   Reply With Quote
Old 25th April 2008, 12:10 AM   (permalink)
Default

Quote:
Originally Posted by desaila
Also, I have it wired in a very similar way. Just a potentiometer instead of a 10k. It wasn't just my professor either, I had the TA double check it prior to firing it up for the first time. It was fine for ~2 weeks and them smoked.
Drifting power wires? Power supply problem? Better start looking for a cause, cuz that smoke thing isn't good.

Quote:
Is that something that can be expected?
NO!
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
COnnecting 2 telephone Sets via optical coupler waqar General Electronics Chat 4 20th April 2008 03:07 AM
Xbox 360 Tilt Controller adamthole Electronic Projects Design/Ideas/Reviews 0 20th January 2007 05:24 PM
closed loop controller that receives set point updates TXRX usacanbiteme Electronic Projects Design/Ideas/Reviews 5 28th September 2005 09:02 PM
Motor controller for a e-motor/generator Combo dreamtoys Electronic Projects Design/Ideas/Reviews 1 3rd October 2003 11:42 PM
Help With Temperature Controller bryan Electronic Projects Design/Ideas/Reviews 4 30th June 2003 12:18 PM



All times are GMT. The time now is 04:24 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.