View Full Version : Programming the NMIY-0031 in C
Hello, I'm new to embedded apps so please bear with me.
I have a NMIY-0031 board that I want to develop some C and assembly programs for. I have an EPROM burner that I want to use to run these programs.
I wrote a small program to print some characters to an LCD display, compiled and assembled it with the supplied software.
I wrote this to a 29C256 EEPROM, but nothing seems to happen when I power up the board. Are there any special steps I need to take?
Please note that I have configured the jumpers on U2 to correspond to a 32x8 ROM. I burned the monitor program to a 29c256 rom and tested that. It works fine. I have also tested the LCD screen by entering commands manually through the monitor program.
I don't have the keypad so I can't use the supplied sample code, but if anyone has a known working sample bin file that I can write to the EEPROM to test this program it would be appreciated.
nmitech
08-14-02, 12:03 PM
AlexH,
If you programmed the monitor code to the 29C256 and it works then you can make any smallC sample program provided to work by edit the Common51.c file as below and re-compile to generate the correct memory map for the new object (hex) file.
; MEMORY MAP for PROM ====================================
.EQU RAM,H'8000 ; starting address of data RAM, NEVER 0!
.EQU STACKTOP,H'9FF0 ; initial stack pointer, MUST BE EVEN!
.EQU ROM,H'0000 ; starting address of program ROM, usually 0
.EQU LITROM,H'6000 ; ROM address where literals will be stored
Thanks for the reply. I'm curious why the stacktop is set to 9FF0, in my old common51.c file it is set to FFD0.
I got it working thanks, I didn't realize that the obj file was an intel hex file. When I specified that in my EEPROM burning software, it worked.
Thanks!
nmitech
08-21-02, 11:35 AM
"I'm curious why the stacktop is set to 9FF0, in my old common51.c file it is set to FFD0."
Because, i assumed your board comes with the 8Kbyte Sram instead of 32Kbyte then you can set the stack top at FBFE, not FFD0. Keep in mind, from FC00 - FFFF are the peripheral chip select registers.
Ok, I have been slowly making progress, but I'm at the step where I want to be doing some things in assembly. Is there an instruction manual anywhere for the PseudoSam assembler?
I noticed that some 8051 tutorials use shortcuts like MOV A, #HIGH CHECK_VALVE where #HIGH means the high byte of a 16bit number. Does PseudoSam support that?
Ok, I have a couple more questions.
I'm wanting to mix some assembly and C code so I can use the timer ISR on my NMIY-0031 board. Is there any way I can put code in the timer 0 ISR area? Whenever I try to put it in this area using ".org H'00B" (I think that is the correct location) my program will not run. It looks like there is space reserved already in this area in the common.c file.
Also, I'd like to use 4 spaces in internal ram for the ISR. Is there any way that I can use this in assembler? Again, when I try to use ".org H'07C" it does not work.
nmitech
09-09-02, 04:45 PM
The program below is provided with the NMIY-0031 distibution diskette. It is C program and mixed with asm routines. Look good for your reference.
Is there an instruction manual anywhere for the PseudoSam assembler?
I noticed that some 8051 tutorials use shortcuts like MOV A, #HIGH CHECK_VALVE where #HIGH means the high byte of a 16bit number. Does PseudoSam support that?
PseudoSam assembler doc does not mention this instruction. Neither, I have try this yet.
/******** EX0 Interrupt driven sample program **************/
/*************************************************************************
To run this program with an 8k-byte sram on U3, the file "common51.c"
needs to be modified the memory map & interrupt vector as below:
; MEMORY MAP FOR U3 RAM DEVELOPMENT =====================================
.EQU RAM,H'8F00 ; starting address of data RAM, NEVER 0!
.EQU STACKTOP,H'8FFE ; initial stack pointer, MUST BE EVEN!
.EQU ROM,H'8000 ; starting address of program on U3 is 8000h
.EQU LITROM,H'8C00 ; literals address
; 8051 RESET AND INTERRUPT VECTORS ==============
LJMP RESET
LJMP .do_ex0_isr
.RS 4
LJMP ..TF0
..TF0: RETI
.RS 4
LJMP ..IE1
..IE1: RETI
.RS 4
LJMP ..TF1
..TF1: RETI
.RS 4
LJMP ..RITI
..RITI: RETI
.RS 4
LJMP ..TF2
..TF2: RETI
**************************************************************************/
#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h
#include clib\fputc.c
#include clib\fputs.c
#include clib\port1.c
int i;
main()
{
enable_ex0();
fputs("\n Pull INT0 low to trigger interrupt. \n",stdout);
while(1)
{
for(i=1; i<=0x100;i*=2)
{
p1poke(i);
delay();
}
}
} /* ---- end of main ----- */
delay()
{
int i;
for(i=0; i < 5000; i++);
}
toggle()
{
fputs("\n PORT1 even-bit high, odd-bit low ",stdout);
p1poke(0xAA);
delay();
fputs("\n PORT1 even-bit low, odd-bit high", stdout);
p1poke(0x55);
delay();
}
#asm
EX0ISR lcall .toggle
reti
#endasm
enable_ex0()
{
#asm
setb ie.7 ;enable global interrupt
setb ie.0 ;enable external interrupt 0
#endasm
}
Ok, this is where I am confused... where is the .do_ex0_isr label (assembly) or function call (C)?
LJMP RESET is 3 bytes, so that takes us to 0003Bh, correct? At that point, the EX0 ISR is at 0003Bh.
3 bytes for the LJMP + 4 bytes from the '.rs 4' takes us to the next ISR at locations 000Bh.
So basically you are just filling up space in the ISR area.
But I am still confused on my previous question:
Also, I'd like to use 4 spaces in internal ram for the ISR. Is there any way that I can use this in assembler? Again, when I try to use ".org H'07C" it does not work.
I may have been unclear. I want to use those 4 bytes to store values in. When I use ".org H'07C", this should be in internal RAM, and I should be able to MOV values to and from this location. Whenever I try this, nothing runs.
nmitech
09-12-02, 08:30 PM
"this is where I am confused... where is the .do_ex0_isr label (assembly) or function call (C)?"
The modified program below will explain where the interrupt service routine is called.
/******** EX0 Interrupt driven sample program **************/
/*************************************************************************
To run this program with an 8k-byte sram on U3, the file "common51.c"
needs to be modified the memory map & interrupt vector as below:
; MEMORY MAP FOR U3 RAM DEVELOPMENT =====================================
.EQU RAM,H'8F00 ; starting address of data RAM, NEVER 0!
.EQU STACKTOP,H'8FFE ; initial stack pointer, MUST BE EVEN!
.EQU ROM,H'8000 ; starting address of program on U3 is 8000h
.EQU LITROM,H'8C00 ; literals address
; 8051 RESET AND INTERRUPT VECTORS ==============
LJMP RESET
LJMP ..IE0 ; <--- Renamed as original
.RS 4
LJMP ..TF0
;..IE0: RETI ; <--- This line must comment out
..TF0: RETI
.RS 4
LJMP ..IE1
..IE1: RETI
.RS 4
LJMP ..TF1
..TF1: RETI
.RS 4
LJMP ..RITI
..RITI: RETI
.RS 4
LJMP ..TF2
..TF2: RETI
**************************************************************************/
#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h
#include clib\fputc.c
#include clib\fputs.c
#include clib\port1.c
/* --- INT0 interrupt service routine --- */
_IE0() /* <--- this routine is called each time INT0 is triggered low */
{
#asm
lcall .toggle
reti
#endasm
}
enable_IE0()
{
#asm
setb ie.7 ;enable global interrupt
setb ie.0 ;enable external interrupt 0
#endasm
}
delay()
{
int d;
for(d=0; d < 5000; d++);
}
toggle()
{
fputs("\n PORT1 even-bit are high, odd-bit are low ",stdout);
p1poke(0xAA);
delay();
fputs("\n PORT1 even-bit are low, odd-bit are high", stdout);
p1poke(0x55);
delay();
}
/* -------- MAIN PROGRAM --------- */
int i;
main()
{
enable_IE0();
fputs("\n Pull INT0 low to trigger interrupt. \n",stdout);
while(1)
{
for(i=1; i<=0x100;i*=2)
{
p1poke(i);
delay();
}
}
}
/* ---- END OF MAIN ----- */
Also, I'd like to use 4 spaces in internal ram for the ISR. Is there any way that I can use this in assembler? Again, when I try to use ".org H'07C" it does not work.
As far as the Internal Ram that you concerned, the 4 byte that reserved in the ISR is the program area, not Internal Ram. Please post your program up here so others can help you out.
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.