P89LPC922 blinking LED help

Thread Starter


Joined Dec 19, 2010

I'm new to the 80C51 family of microcontrollers, although I have worked with PIC18F microcontrollers a long time ago. I'm trying to get started with the P89LPC922 in a 20-pin DIP package. I'm just trying to get a "Hello World" type project up and running. The system should blink and LED on and off at a rate detectable to a human. I wired up the hardware, wrote the firmware and programmed the device, but it doesn't seem to do anything.

I have 3.6V on pins 4 (active low reset) and 15 (VDD), and I have ground on pin 5 (VSS). I'm using pin 2 (P1.7) to blink the light. All other pins are not connected. If I disconnect from the microcontroller and apply 3.6V directly to the LED, it lights with less than 10mA of current used.

Below is the C code I used for the firmware. The header file just gives the locations of the SFRs. I'll post it if anyone wants to see it. I compiled the source down to an intel hex file with SDCC.
Rich (BB code):
#include <P89LPC922.h>

void main()
    long i;

    // Configure Port 1 bit 7 in push-pull output mode
    P1M1 = 1;
    P1M2 = 0;

    P1_7 = 1;   // Turn on LED
    while(1) // Main loop
        for(i=1;i<100000;i++);  // Delay so human can see
        P1_7 = !P1_7;  // Toggle LED
I programmed the microcontroller with a Galep-5 universal programmer. The programmer reports that programming is successful. The configuration byte is 0x63, which disables the watchdog timer and selects the internal RC oscillator, among other things.

When power is applied, the LED remains off. I have 3.6V on pins 4 and 15 and 0V on pin 5. The other pins including pin 2 seem to stay around 0.3V, but they wander, sometimes a high as a volt. I'm not sure what do try next.

Thread Starter


Joined Dec 19, 2010

I found a solution at http://forum.best-microcontroller-projects.com/viewtopic.php?f=5&t=2060&p=2773#p2773

In case that website ever becomes unavailable, I'll re-post the answer here.

Hi, Kev. Thanks for your reply. You got it! I made a couple of mistakes. As you pointed out, I have P1M1 and P1M2 backwards. Also, in my C code the lines
Rich (BB code):
   P1M1 = 1;
   P1M2 = 0;
set all the P1M2 bits to 0, but only sets bit 0 of P1M1 to 1, not what I intended. I found a nice website, http://www.codearchitect.org, that generates C code for the P89LPC922, among other microcontrollers, that would have prevented this mistake. I changed the code above to
Rich (BB code):
  P1M1 &= 0x7F;
  P1M2 |= 0x80;
, which the codearchitect website suggested.

For anyone else that may be having trouble getting started with this microcontroller, here are a few other things I found. The default behavior of this chip is to start executing code at the boot ROM vector rather than 0x0000. It turns out that my programmer was changing that configuration so that it would start executing at 0x0000, but someone with a different programming method might have this problem. I also tried putting 15uF capacitors between my power and ground rails. It didn't make a difference with my power supply and circuit, but I've seen this technique solve strange circuit problems in the past. I'm also posting the header file, P89LPC922.h, below, so that anyone looking for help and running across this thread will have a complete solution to getting up and running with the P89LPC922:
Rich (BB code):
This header allows to use the microcontroler Philips P89LPC922
with the compiler SDCC.

Copyright (c) 2005 Omar Espinosa--e-mail: opiedrahita2003 AT yahoo.com.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

Archivo encabezador para el ucontrolador Philips P89LPC922.
Derechos de copy (DC) 2005.  OMAR ESPINOSA P.  E-mail: opiedrahita2003 AT yahoo.com
Uso libre
#ifndef __REG922_H__
#define __REG922_H__

//*  BYTE Registers  *//
__sfr __at (0x80) P0     ;
__sfr __at (0x90) P1     ;
__sfr __at (0xB0) P3     ;
__sfr __at (0xD0) PSW    ;
__sfr __at (0xE0) ACC    ;
__sfr __at (0xF0) B      ;
__sfr __at (0x81) SP     ;
__sfr __at (0x82) DPL    ;
__sfr __at (0x83) DPH    ;
__sfr __at (0x87) PCON   ;
__sfr __at (0x88) TCON   ;
__sfr __at (0x89) TMOD   ;
__sfr __at (0x8A) TL0    ;
__sfr __at (0x8B) TL1    ;
__sfr __at (0x8C) TH0    ;
__sfr __at (0x8D) TH1    ;
__sfr __at (0xA8) IEN0   ;
__sfr __at (0xB8) IP0    ;
__sfr __at (0x98) SCON   ;
__sfr __at (0x99) SBUF   ;

__sfr __at (0xA2) AUXR1  ;
__sfr __at (0xA9) SADDR  ;
__sfr __at (0xB9) SADEN  ;
__sfr __at (0xBE) BRGR0  ;
__sfr __at (0xBF) BRGR1  ;
__sfr __at (0xBD) BRGCON ;
__sfr __at (0xAC) CMP1   ;
__sfr __at (0xAD) CMP2   ;
__sfr __at (0x95) DIVM   ;
__sfr __at (0xE7) FMADRH ;
__sfr __at (0xE6) FMADRL ;
__sfr __at (0xE4) FMCON  ;
__sfr __at (0xE5) FMDATA ;
__sfr __at (0xDB) I2ADR  ;
__sfr __at (0xD8) I2CON  ;
__sfr __at (0xDA) I2DAT  ;
__sfr __at (0xDD) I2SCLH ;
__sfr __at (0xDC) I2SCLL ;
__sfr __at (0xD9) I2STAT ;
__sfr __at (0xF8) IP1    ;
__sfr __at (0xF7) IP1H   ;
__sfr __at (0x94) KBCON  ;
__sfr __at (0x86) KBMASK ;
__sfr __at (0x93) KBPATN ;
__sfr __at (0x84) P0M1   ;
__sfr __at (0x85) P0M2   ;
__sfr __at (0x91) P1M1   ;
__sfr __at (0x92) P1M2   ;
__sfr __at (0xB1) P3M1   ;
__sfr __at (0xB2) P3M2   ;
__sfr __at (0xB5) PCONA  ;
__sfr __at (0xF6) PT0AD  ;
__sfr __at (0xDF) RSTSRC ;
__sfr __at (0xD1) RTCCON ;
__sfr __at (0xD2) RTCH   ;
__sfr __at (0xD3) RTCL   ;
__sfr __at (0xBA) SSTAT  ;
__sfr __at (0x8F) TAMOD  ;
__sfr __at (0x96) TRIM   ;
__sfr __at (0xA7) WDCON  ;
__sfr __at (0xC1) WDL    ;
__sfr __at (0xC2) WFEED1 ;
__sfr __at (0xC3) WFEED2 ;
__sfr __at (0xB7) IP0H   ;
__sfr __at (0xE8) IEN1   ;

/*  BIT Registers  */
/*  PSW   */
__sbit __at (0xD0) PSW_0   ;
__sbit __at (0xD1) PSW_1   ;
__sbit __at (0xD2) PSW_2   ;
__sbit __at (0xD3) PSW_3   ;
__sbit __at (0xD4) PSW_4   ;
__sbit __at (0xD5) PSW_5   ;
__sbit __at (0xD6) PSW_6   ;
__sbit __at (0xD7) PSW_7   ;

#define CY    PSW_7
#define AC    PSW_6
#define F0    PSW_5
#define RS1   PSW_4
#define RS0   PSW_3
#define OV    PSW_2
#define F1    PSW_1
#define P     PSW_0

/*  TCON  */
__sbit __at (0x8F) TCON_7  ;
__sbit __at (0x8E) TCON_6  ;
__sbit __at (0x8D) TCON_5  ;
__sbit __at (0x8C) TCON_4  ;
__sbit __at (0x8B) TCON_3  ;
__sbit __at (0x8A) TCON_2  ;
__sbit __at (0x89) TCON_1  ;
__sbit __at (0x88) TCON_0  ;

#define TF1   TCON_7
#define TR1   TCON_6
#define TF0   TCON_5
#define TR0   TCON_4
#define IE1   TCON_3
#define IT1   TCON_2
#define IE0   TCON_1
#define IT0   TCON_0

/*  IEN0   */
__sbit __at (0xAF) IEN0_7  ;
__sbit __at (0xAE) IEN0_6  ;
__sbit __at (0xAD) IEN0_5  ;
__sbit __at (0xAC) IEN0_4  ;
__sbit __at (0xAB) IEN0_3  ;
__sbit __at (0xAA) IEN0_2  ;
__sbit __at (0xA9) IEN0_1  ;
__sbit __at (0xA8) IEN0_0  ;

#define EA    IEN0_7
#define EWDRT IEN0_6
#define EBO   IEN0_5
#define ES    IEN0_4    // alternatively "ESR"
#define ESR   IEN0_4
#define ET1   IEN0_3
#define EX1   IEN0_2
#define ET0   IEN0_1
#define EX0   IEN0_0

/*  IEN1   */
__sbit __at (0xEA) IEN1_2  ;
__sbit __at (0xE9) IEN1_1  ;
__sbit __at (0xE8) IEN1_0  ;

#define EC    IEN1_2
#define EKBI  IEN1_1
#define EI2C  IEN1_0

/*  IP1   */
__sbit __at (0xFE) IP1_6   ;
__sbit __at (0xFA) IP1_2   ;
__sbit __at (0xF9) IP1_1   ;
__sbit __at (0xF8) IP1_0   ;

#define PST   IP1_6
#define PC    IP1_2
#define PKBI  IP1_1
#define PI2C  IP1_0

/*  IP0   */
__sbit __at (0xBE) IP0_6   ;
__sbit __at (0xBD) IP0_5   ;
__sbit __at (0xBC) IP0_4   ; // alternatively "PSR"
__sbit __at (0xBB) IP0_3   ;
__sbit __at (0xBA) IP0_2   ;
__sbit __at (0xB9) IP0_1   ;
__sbit __at (0xB8) IP0_0   ;

#define PWDRT IP0_6
#define PBO   IP0_5
#define PS    IP0_4      // alternatively "PSR"
#define PSR   IP0_4
#define PT1   IP0_3
#define PX1   IP0_2
#define PT0   IP0_1
#define PX0   IP0_0

/*  SCON  */
__sbit __at (0x98) SCON_0  ;
__sbit __at (0x99) SCON_1  ;
__sbit __at (0x9A) SCON_2  ;
__sbit __at (0x9B) SCON_3  ;
__sbit __at (0x9C) SCON_4  ;
__sbit __at (0x9D) SCON_5  ;
__sbit __at (0x9E) SCON_6  ;
__sbit __at (0x9F) SCON_7  ;

#define SM0   SCON_7  // alternatively "FE"
#define FE    SCON_7
#define SM1   SCON_6
#define SM2   SCON_5
#define REN   SCON_4
#define TB8   SCON_3
#define RB8   SCON_2
#define TI    SCON_1
#define RI    SCON_0

/*  I2CON  */
__sbit __at (0xDE) I2CON_6 ;
__sbit __at (0xDD) I2CON_5 ;
__sbit __at (0xDC) I2CON_4 ;
__sbit __at (0xDB) I2CON_3 ;
__sbit __at (0xDA) I2CON_2 ;
__sbit __at (0xD8) I2CON_0 ;

#define I2EN  I2CON_6
#define STA   I2CON_5
#define STO   I2CON_4
#define SI    I2CON_3
#define AA    I2CON_2
#define CRSEL I2CON_0

/*  P0    */
__sbit __at (0x80) P0_0    ;
__sbit __at (0x81) P0_1    ;
__sbit __at (0x82) P0_2    ;
__sbit __at (0x83) P0_3    ;
__sbit __at (0x84) P0_4    ;
__sbit __at (0x85) P0_5    ;
__sbit __at (0x86) P0_6    ;
__sbit __at (0x87) P0_7    ;

#define KB7   P0_7   // alternatively "T1"
#define T1    P0_7
#define KB6   P0_6   // alternatively "CMP1"
#define CMP1  P0_6
#define KB5   P0_5
#define KB4   P0_4
#define KB3   P0_3
#define KB2   P0_2
#define KB1   P0_1
#define KB0   P0_0   // alternatively "CMP2"
#define CMP2  P0_0

/*  P1  */
__sbit __at (0x90) P1_0    ;
__sbit __at (0x91) P1_1    ;
__sbit __at (0x92) P1_2    ;
__sbit __at (0x93) P1_3    ;
__sbit __at (0x94) P1_4    ;
__sbit __at (0x95) P1_5    ;
__sbit __at (0x96) P1_6    ;
__sbit __at (0x97) P1_7    ;

#define RST   P1_5
#define INT1  P1_4
#define INT0  P1_3   // alternatively "SDA"
#define SDA   P1_3
#define T0    P1_2   // alternatively "SCL"
#define SCL   P1_2
#define RxD   P1_1
#define TxD   P1_0

/*  P3  */
__sbit __at (0xB0)  P3_0   ;
__sbit __at (0xB1)  P3_1   ;

#define XTAL1 P3_1
#define XTAL2 P3_0

Thanks again, Kev!