Flash Magic Forum

In-System Programming Support => P89V51Rx2/P89LV51Rx2 => Topic started by: Craig on June 14, 2006, 12:35:10 AM

Title: P89V51RD2BN
Post by: Craig on June 14, 2006, 12:35:10 AM
Dear Sirs,

I am a 2nd year Instrumentation student.  I am very keen
on studying microcontrollers n so I bought a kit for $9/-.
The kit has a Philips P89V51RD2BN chip, a 12.0 Mhz Xtal
and a Max 232 chip in the Serial circuitry.  P0, P1 n P2
are taken to VCC thru 4.7K res. banks.

My aim for this holiday session is to load a program on to
the chip. I have Philips "Flash Magic" and have got Flash
to communicate with the chip i.e. it read the chip signature.

I have very limited sources for studying assembly
programming and so I have not yet got down to writing
programs myself.  I have 2 ready programs taken from
Myke Predko's book "Programming n Customizing 8051 MC".

Program 1 is a State Machine program written for a
DS80C320 chip (I understand that this chip is just a faster
version of the 80C51 but I'm not sure if I could just load
this program onto my chip and see it run).  I request you
to alter this program for my chip (P89V51RD2BN) if
necessary and also re-write the Dlay to give me 5sec delays.
I've written in a delay from my limited understanding
but it's not slow enough.

Program 2 is a pseudo random generator for Christmas
lights written for a DS87C520 chip.  Again cud u please
alter the program if necessary for my chip.

Once I get these programs running on my chip I will
have achieved my initial holiday target, I then intend
to get into assembly programming, hopefully I will
soon be writing efficient programs myself.

I am using UMPS (an IDE) but they have not included
the Philips chips in their library hence I could not
check this out for myself.  Would you know of a "free"
demo IDE for the Philips chips (P89V51RD2BN included).

Also is there any material I can use to study assembly
for Microcontrollers (everything seems to be written for
the 80x86 series).

Many thanks.

Hope to hear from you soon,



Lionel Craig D'Silva


PS - Attached are the two programs
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;  PROG1 - State Machines
;
;  This Application Demonstrates how a set of traffic lights could
;   be controlled in the 8051 using a State Machine and Table Jumps.  
;
;  This program will run in the UMPS simulator for a DS80C320.
;
;  Myke Predko
;  98.02.18
;
;  Hardware Notes:
;   This program is only meant to run on the Simulator
;    It could be modified to run in hardware by making "Dlay" more than
;    a dummy routine
;
;  North/South Lights
;   NSGreen  - P1.0
;   NSYellow - P1.1
;   NSRed    - P1.2
;
;  East/West Lights
;   EWGreen  - P1.4
;   EWYellow - P1.5
;   EWRed    - P1.6

;  Variable Declarations
State EQU 020h         ;  The Current State Variable
StateDir EQU 004h               ;  The Direction Bit - Bit 4 of 020h
;  Bit States
;   Bit 4: _EW/NS - This Bit is Set for NS, Reset for East/West
;   Low Nybble: Current Light State


;  R0 is used as an Index Pointer to Array
;  R1 is used as the Source Location for the Control Store Table

Array EQU 0B0h         ;  Define Array in Scratchpad RAM

;  Mainline
 org 0                          ;  Execution Starts Here

  mov    State,#0      ;  Start with E/W "Red"

  mov    P1,#0BBh               ;  Turn on the Red Lights

  mov    DPTR,#LightTable   ;  Have the DPTR Point to the

Loop:            ;  Loop Back Here for Each Light State

  acall    NextLight

  sjmp    Loop


NextLight:         ;  Now, Turn Off the Current Light and Turn
            ;   The Next One
  mov    A,State      ;  Get the State x2
  rl    A
  anl    A,#0DFh      ;  Clear the _EW/NS Flag

  jmp    @A+DPTR      ;  Jump to the Appropriate Response

LightTable:

  sjmp    GreenLight      ;  Currently Have a Red Light, Go to Green
  sjmp    YellowLight      ;  Currently Have a Green Light, Go to Yellow
  sjmp    RedLight      ;  Currently Have a Yellow Light, Go to Red

GreenLight:         ;  Turn the Light to Green

  mov    A,#0EBh      ;  Are We turning on the E/W Light
  jnb    StateDir,GL_EW
  mov    A,#0BEh      ;   No - Do the North South
GL_EW:
  mov    P1,A         ;  Now, Turn on the Light

  mov    R0,#6         ;  Delay for a Green Light Period
  acall    Dlay

  inc    State         ;  Increment to the Next State

  ret

YellowLight:         ;  Turn the Light to Yellow

  mov    A,#0DBh      ;  Are We turning on the E/W Light
  jnb    StateDir,YL_EW
  mov    A,#0BDh        ;   No - Do the North South
YL_EW:
  mov    P1,A         ;  Now, Turn on the Light

  mov    R0,#6      ;  Delay for a Yellow Light Period
  acall    Dlay

  inc    State         ;  Increment to the Next State

  ret

RedLight:         ;  Turn the Light to Red

  mov    P1,#0BBh      ;  Turn Everything to Red

  mov    R0,#6         ;  Delay for a Red Light Period
  acall    Dlay

  mov    A,#0F0h      ;  Reset back to Green for the Next Light
  anl    State,A

  cpl    StateDir      ;  Change Which Light is Active

  ret


Dlay:            ;  Delay a Set amount of Time for Each Light
  mov  R0,#6
  mov  R2,#255

DlayLoop:

  djnz R0,DlayLoop
  djnz R2,DlayLoop
 
  ret
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------

;  PROG2 - Psuedo-Random LED Display
;
;  This Application Displays a psuedo Random 16 Bit Number
;   Generated by a single Tap CRC at Bit 10 (XOR'd with Bit 15).
;
;  The LSB is Bit 10 ^ Bit 15
;           = ( !Bit 10 & Bit 15 ) | ( Bit 10 & !Bit 15 )
;
;  This algorithm will give about 61K Different Patterns
;  
;  A Quarter Second Delay is placed between Every New LED Pattern.  
;
;  This display is suitable for Doing Christmas Lights.  
;
;  Myke Predko
;  98.02.22
;
;  Hardware Notes:
;  80C520 Running at 4 MHz
;  P1.0-7 Connected to LEDs
;  P3.0-7 Connected to LEDs

;  Variable Declarations
;  Just "A" is used for this program.  

;  Mainline
 org 0                          ;  Execution Starts Here

Loop:                           ;  Loop Here Forever

  mov    C,P3.2                 ;  Get the Bits to AND Together
  cpl    PSW.7                  ;   Invert Bit 13
  anl    C,P3.7                 ;   AND it with Bit 15
  mov    ACC.0,C                ;  Save it for Later

  mov    C,P3.7                 ;  Now, Get Bit13 * !Bit15
  cpl    PSW.7
  anl    C,P3.2

  orl    C,ACC.0                ;  OR Both Values Together in Carry

  mov    A,P1                   ;  Now, Update the 16 LED Display
  rlc    A
  mov    P1,A
  mov    A,P3
  rlc    A
  mov    P3,A

  acall  Dlay                   ;  Leave Like this for 500 msec

  sjmp   Loop                   ;  Loop Around Again

Dlay:                           ;  Delay 263 msec

  clr    A
  mov    B,#0                   ;  Longest Delay Possible

DlayLoop:                       ;  Loop Here for 500 msec
  djnz   ACC,DlayLoop           ;  Inside Loop
  djnz   B,DlayLoop

  ret
Title: Re: P89V51RD2BN
Post by: Andy Ayre on June 14, 2006, 07:56:42 AM
Great post, and good luck with your projects, but this forum is for discussion of ISP issues. If you have a problem or questions on ESAcademy material please email us. If you have general 8051 questions or problems try the discussion forum at 8052.com.