|
Hi, I need suggestions to debug a program. The problem is that the program stops after about two minutes. The program does an analog conversion on the voltages at PE1 through PE7, converts them to BCD and then ASCII and lastly displays the voltages on a Hitachi 4 lines X 20 character LCD. The program operates as expected for several minutes then stops. I have checked the stack to see if there is an overflow. Nothing unusual. Only about 10 bytes were used. Any and all ideas are welcome. Nick |
|
|
|
Hi Just a thought check out any unused interrupts eg. XIRQ etc. If the pin is not pulled hi the CMOS input might drift around and eventually cause an interrupt which you havn't defined so anything could happen Mike Dunning At 22:44 23/02/03 -0800, you wrote: >Hi, >I need suggestions to debug a program. The problem is that the program stops >after about two minutes. >The program does an analog conversion on the voltages at PE1 through PE7, >converts them to BCD and then ASCII and lastly displays the voltages on a >Hitachi 4 lines X 20 character LCD. >The program operates as expected for several minutes then stops. I have >checked the stack to see if there is an overflow. Nothing unusual. Only >about 10 bytes were used. >Any and all ideas are welcome. > >Nick > > >To unsubscribe from this group, send an email to: |
|
In a message dated 2/23/03 10:38:15 PM Eastern Standard Time, writes: > The program operates as expected for several minutes then stops. I have > checked the stack to see if there is an overflow. Nothing unusual. Only > about 10 bytes were used. > Any and all ideas are welcome. Post the program. A bunch of smart guys will stare at it. You'll be sure to get lots of 'constructive' criticism.... [Non-text portions of this message have been removed] |
|
Some suggestions: * Define "the program stops". Does it really stop or seem like it doesn't do what's expected. If it truly stops, check oscillator, etc. If not, what does it do, random code execution (e.g., some garbage shows up on the LCD)? Does it always fail in exactly the same way (e.g., exact number of A/D readings, etc.) * Use a simulator to catch some types of software bugs that aren't easy to 'see' in real execution. * Like someone else mentioned, check /IRQ, /XIRQ, or even any possibly floating pins changing state after a while causing a different (unintended) execution. * Initialize all unused vectors to separate simple ISRs that somehow (e.g., LCD) display the vector ID and maybe even the stacked PC value. This will catch any unexpected ISR triggers. * Try reducing your code to the point where it's just a couple of routines (one to read the A/D, and one to write to the LCD), then run this in an endless loop. If the problem vanishes, you most likely have a coding error someplace in your larger application. * Try without the LCD code (using a blinking LED, perhaps to verify code is still running). If it works, problem is narrowed to the LCD code. * Try without the A/D code. Just write continuously on the LCD 'random' strings. If it works, problem is narrowed to the A/D code. * Use a different MCU (on occasion you might hit a bad chip). Use a different board - prototype or production - you could have an intermittent hardware error. * Send us your reduced code as a complete program -- but not necessarily the whole 50000 line application -- it could be something obvious to the rest of us. A 'third eye' often sees things we don't. ----- Original Message ----- From: Nick Reitter, 3rd <> To: <> Sent: Monday, February 24, 2003 8:44 AM Subject: [m68HC11] Need debugging techniques on ADC to LCD > Hi, > I need suggestions to debug a program. The problem is that the program stops > after about two minutes. > The program does an analog conversion on the voltages at PE1 through PE7, > converts them to BCD and then ASCII and lastly displays the voltages on a > Hitachi 4 lines X 20 character LCD. > The program operates as expected for several minutes then stops. I have > checked the stack to see if there is an overflow. Nothing unusual. Only > about 10 bytes were used. > Any and all ideas are welcome. > > Nick |
|
In a message dated 2/24/03 9:45:58 PM Eastern Standard Time, writes: > Any and all ideas are welcome. > RAM EQU $0100 ;Beginning of RAM variables Code EQU $b600 ;Beginning of code area STACK EQU $0FFF ;put the stack at the top of the user RAM I looked at the ram and rom in the adapt11c24dx60... looks like its got 32k of rom from 0x8000 to 0xffff and 28k of external ram from 0x1000 to 0x7fff, E) processor has 512 bytes of internal ram 0x0000 to 0x01ff..... so right off the bat, I'd be setting RAM to 0x1000, Code to 0x8000, and STACK to 0x01ff (end of internal ram), ot 0x7fff (end of external ram). Whats this bit about the program goes in at 0xe000 and goes round and round and comes out here at 0xb600?? [Non-text portions of this message have been removed] |
|
|
|
I have tied the following pins high through a 10K resistor: IRQ, XIRQ, RESET, STRB,STRB(R/W),E and AS. The program stops after a few minutes. I still have to try the "dissecting" debugging technique suggested by Tony. Here is the code for displaying 6 voltages on the LCD............... * LCD_Volt.asm - February 15, 2003 *Adapt11C24DX60K, from Technological Arts *PE0 is high. The code initially goes to $E000 and then to $B600 *via the monitor program *Six analog voltages will be displayed on the LCD using a decimal value *PE1,2,3,4,5,6; VRH should be = 5.12 Volts *Two programs were combined: Ex714_0.asm and LCDAd11a.asm * The LCD tested was a PWB 20434-CEM, OPTEX .(Purchased from ALL Electronics) * Display four rows of ASCII characters on a 20 X 4 LCD display * The display must be using a HD44780 or equivalent controller chip * Characters are copied from the 68HC11 memory area to DDRAM * Use the free-running counter TCNT for time delays * this program is based on these connections between the 68HC11 and the HD44780: * PB7 -- DB7 PB3 -- DB3 PA6 -- EN * PB6 -- DB6 PB2 -- DB2 PA5 -- R/W * PB5 -- DB5 PB1 -- DB1 PA4 -- RS * PB4 -- DB4 PB0 -- DB0 * ............................................................................ .. * Program Equates: * DDRAM addresses used by this display, bit 7 must be a 1 ADDR00 EQU %10000000 ;DDRAM address 00h ADDR40 EQU %11000000 ;DDRAM address 40h ADDR14 EQU %10010100 ;DDRAM address 14h ADDR54 EQU %11010100 ;DDRAM address 54h * Number of characters per logical line for this display NUMCHAR EQU 20 ;20 characters per logical line* *Memory allocations RAM EQU $0100 ;Beginning of RAM variables Code EQU $b600 ;Beginning of code area STACK EQU $0FFF ;put the stack at the top of the user RAM * HD44780 Instructions for this display and program RESET EQU %00110000 ;sent 3 times to reset display CLEAR EQU %00000001 ;clear display HOME EQU %00000010 ;return cursor to home position MODE EQU %00000110 ;shift cursor from left to right on read/write DISPOFF EQU %00001000 ;display off, cursor off, don't blink character SHIFT EQU %00010100 ;shift cursor to right without changing RAM FUNCT EQU %00111000 ;8 bit data, 4 line display, 5 x 7 font DISPON EQU %00001100 ;display on, cursor off, don't blink character * Control signals EN EQU %01000000 ;LCD Enable line RW EQU %00100000 ;LCD Read/Write line, 1 = write, 0 = read RS EQU %00010000 ;LCD Register Select line, 1 = character, 0 = instruction * Delay data (assuming a 2 MHz system clock) D40US EQU 80 ;data for 40 uSec overall time delay D100US EQU 200 ;data for 100 uSec overall time delay D1P6MS EQU 3200 ;data for 1.6 mSec overall time delay D4P1MS EQU 8200 ;data for 4.1 mSec overall time delay D15MS EQU 30000 ;data for 15 mSec overall delay time D30MS EQU 60000 ;data for 30 mSec * System Equates: REGBAS EQU $1000 ;base address of registers PORTA EQU $00 ;offset to I/O Port A PORTB EQU $04 ;offset to Output PORT B TCNT EQU $100E ;actual address of free running counter TCNT * *RAM allocation *$0100 RAM variables *$0FFF location of the top of stack *$b600 beginning of code EEPROM *Memory buffer ORG RAM DLYDTA RMB 4 ;storage for delay data FSN0 RMB 1 FSN RMB 1 ;First Significant Number SSN RMB 1 ;Second Significant Number TSN RMB 1 ;Third Significant Number TSNB RMB 1 *Program in Code memory ORG Code BRA Start ;leap over the embedded info FCB "4 voltages displayed on the LCD" Start: LDX #REGBAS BSET $39,X,$80 ;ADPU bit set to turn on A/D LDS #Stack ;Top of RAM for the stack *The ASCII code from LINE1, LINE2, LINE3 and LINE4 *is copied to RAM at location $0100 *These Lines are located at the very end of the program. *They are copied here for ease of seeing. *The x's are place holders *LINE1 FCC 'Voltages on Port E ' *LINE2 FCC 'PE1=x.xxV PE2=x.xxV' *LINE3 FCC 'PE3=x.xxV PE4=x.xxV' *LINE4 FCC 'PE5=x.xxV PE6=x.xxV' LDY #$0110 ;RAM location of Lines to be displayed LDX #LINE1 ;Source of ASCII information LDAB #80 ;4 lines x 20 characters Load: LDA 0,x ;Retrieve ASCII character to AccA STA 0,y ;PLace ASCII in RAM inx ;point to next ASCII char iny ;point to next RAM location DECB ;update counter BNE Load ;do it until all chars have been copied * reset and initialize the LCD controller chip JSR LCDINIT ;initialize the LCD Controller Chip for an 8-Bit interface *Analog Voltages are converted, converted to BCD then ASCII *************************************************** *PE1Volt Loop: LDAA #$21 ;A/D control word LDX #$0110+24 JSR Convert *************************************************** *PE2Volt LDAA #$22 ;A/D control word LDX #$0110+35 JSR Convert *************************************************** *PE3Volt: LDAA #$23 ;A/D control word LDX #$0110+44 JSR Convert *************************************************** *PE4Volt LDAA #$24 ;A/D control word LDX #$0110+55 JSR Convert ***************************************************** *PE5Volt: LDAA #$25 ;A/D control word LDX #$0110+64 JSR Convert *************************************************** *PE6Volt LDAA #$26 ;A/D control word LDX #$0110+75 JSR Convert ***************************************************** LDY #20 * 600 mS delay to allow the LCD to refresh Time: LDD #D30MS ;data for 30 mS delay JSR DELAY DEY BNE Time *The ASCII data in Line1, Line2, Line3 and Line4 is placed on the LCD * display the first group of ASCII characters stored in the 68HC11 memory LDX #LINE1 ;point to beginning of message to be displayed LDAA #ADDR00 ;point to initial DDRAM address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * display the next group of ASCII characters stored in the 68HC11 memory LDX #$0110+20 ;point to beginning of message to be displayed LDAA #ADDR40 ;increment address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * display the next group of ASCII characters stored in the 68HC11 memory LDX #$0110+40 ;point to beginning of message to be displayed LDAA #ADDR14 ;point to initial DDRAM address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * display the next group of ASCII characters stored in the 68HC11 memory LDX #$0110+60 ;point to beginning of message to be displayed LDAA #ADDR54 ;increment address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * Go back and repeat the cycle to display more voltages jmp Loop ************************************************************* * subroutines * this routine initialize the LCD Controller Chip for an 8-Bit interface LCDINIT PSHX ;preserve registers PSHB PSHA * set E, RS, and R/W low LDX #REGBAS ;point to base of I/O register block BCLR PORTA,X RS ;select the instruction register BCLR PORTA,X RW ;select the write mode BCLR PORTA,X EN ;clear the enable bit * initial 15 mS delay LDD #D15MS ;data for 15 mS delay JSR DELAY ;wait at least 4.1 mS * do a software reset by sending three Sequential Function Set instructions LDAA #RESET ;send first reset instruction JSR TOLCD ;write the instruction LDD #D4P1MS ;data for 4.1 mS delay JSR DELAY ;wait at least 4.1 mS LDAA #RESET ;send reset instruction again JSR TOLCD ;write the instruction LDD #D100US ;data for 100 uS delay JSR DELAY ;wait at least 100 uS LDAA #RESET ;send reset instruction a third time JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * controller initialization * Function Set instruction LDAA #FUNCT ;set 8-bit mode, display lines, font JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * Display On/Off Control instruction LDAA #DISPON ;display on, cursor off, don't blink JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * Clear Display instruction LDAA #CLEAR ;clear the display ram JSR TOLCD ;write the instruction LDD #D1P6MS ;data for 1.6 mS delay JSR DELAY ;wait at least 1.6 mS * Entry Mode Set instruction LDAA #MODE ;set the entry mode JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * Cursor to Home position LDAA #HOME ;cursor to home JSR TOLCD ;write the instruction LDD #D1P6MS ;data for 1.6 mS delay JSR DELAY ;wait at least 1.6 mS PULA ;restore registers PULB PULX RTS ;LCD Controller Chip initialization is complete * this routine copies data from EVB RAM to HD44780 DDRAM * enter with: (A) = first destination (DDRAM) address * (B) = number of characters to be displayed * (X) = address of first character in source string DISPLY PSHX ;preserve registers PSHY PSHB PSHA * prepare to send instructions LDY #REGBAS ;point to base of I/O register block BCLR PORTA,Y RS ;select the instruction register * set the DDRAM address JSR TOLCD ;write the instruction PSHA ;preserve DDRAM address PSHB ;preserve number of characters LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS PULB ;restore number of characters PULA ;restore DRAM address * prepare to send characters BSET PORTA,Y RS ;select the character register DISPLY1 LDAA $0,X ;get ASCII code from EVB RAM JSR TOLCD ;write the character PSHA ;save registers PSHB LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS PULB ;restore registers PULA INX ;update message pointer DECB ;update the character counter BNE DISPLY1 ;continue until logical line is full PULA ;restore registers PULB PULY PULX RTS * this routine sends data to the LCD * enter with: (A) = the desired instruction or character * RW low * RS at the required level, 0 for instructions or 1 for characters TOLCD PSHX ;preserve registers LDX #REGBAS ;point to base of I/O register block STAA PORTB,X ;output the character NOP ;140 nSec delay BSET PORTA,X EN ;set the enable bit NOP ;450 nSec time delay BCLR PORTA,X EN ;clear the enable bit NOP ;remainder of 1000 nS Enable Cycle Time PULX ;restore registers RTS ;done * this routine is a general purpose hardware time delay using TCNT * arrive here with (D) = delay data (number of clock pulses for desired delay) * destroys (D) DELAY ADDD TCNT ;determine desired value of TCNT DELAY1 CPD TCNT ;compare current TCNT with desired TCNT BLS DELAY1 ;wait until desired TCNT > current TCNT DELAY2 CPD TCNT ;compare current TCNT with desired TCNT BHI DELAY2 ;repeat until current TCNT > desired TCNT RTS ;done ****************************************************** *Accumulator A must contain the bit pattern for PEx, *the location showing where the voltage is connected Convert: STAA $1030 ;Initialize ADCTL register ;wait for conversion to be complete PSHX LDX #REGBAS Here BRCLR $30,x, $80, Here ;CCF flag musut be a 1 LDAA $1031 ;Read A/D register LDAB #$14 ;Load multiplier $14 (20dec) MUL ;Multiply (Input data) x $14 D LDX #10000 ;Load divisor 10,000 (2710hex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB FSN0 ;Store quotient in memory buffer XGDX ;Return remainder back to D LDX #1000 ;Load divisor 1,000 (3E8hex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB FSN ;Store quotient in memory buffer XGDX ;Return remainder back to D LDX #100 ;Load divisor 100 (64hex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB SSN ;Store quotient in memory buffer XGDX ;Return remainder back to D LDX #10 ;Load divisor 10 (Ahex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB TSN ;Store quotient in memory buffer XGDX ;Return remainder back to D STAB TSNB ;Store quotient in memory buffer LDAA FSN ;Load first significant number ADDA #$30 ;Convert to ASCII PULX ;Retrieve location of Line# STA 0,X ;Place 1st significant number in LCD ram area LDAA SSN ;Load second value ADDA #$30 ;Convert to ASCII INX INX STA 0,X ;Place 2nd significant number in LCD ram area LDAA TSN ;Load third value ADDA #$30 ;Convert to ASCII INX STA 0,X ;Place 3rd significant number in LCD ram area RTS ************************************************************ ************************************************************ * ASCII codes to be displayed, 4 lines X 20 characters * Must have 20 characters between 's *The x's are place holders *These Lines are copied to RAM at $0100 LINE1 FCC 'Voltages on Port E ' LINE2 FCC 'PE1=x.xxV PE2=x.xxV' LINE3 FCC 'PE3=x.xxV PE4=x.xxV' LINE4 FCC 'PE5=x.xxV PE6=x.xxV' -----Original Message----- From: Nick Reitter, 3rd [mailto:] Sent: Sunday, February 23, 2003 10:44 PM To: Subject: [m68HC11] Need debugging techniques on ADC to LCD Hi, I need suggestions to debug a program. The problem is that the program stops after about two minutes. The program does an analog conversion on the voltages at PE1 through PE7, converts them to BCD and then ASCII and lastly displays the voltages on a Hitachi 4 lines X 20 character LCD. The program operates as expected for several minutes then stops. I have checked the stack to see if there is an overflow. Nothing unusual. Only about 10 bytes were used. Any and all ideas are welcome. Nick To unsubscribe from this group, send an email to: |
|
Answer to your question about :- >>> Whats this bit about the program goes in at 0xe000 and goes round and round and comes out here at 0xb600?? The M68HC11E1CFN3 has the Buffalo Monitor in ROM. The monitor program is located at $E000. When PE0 is high, The monitor program PE0. If low the monitor program runs if high the code located at $B600 (EEPROM) runs.. (The address Motorola came up with when they did the monitor program.) Would be better to use $8000, but can not get there conveniently with the way the Monitor program is structured. Stack at $01FF or $7FFF would work also. Stack at $0FFF should not create a problem. RAM at $1000 would conflict with the internal registers. I chose $0100 to get away from the Monitor RAM variables below $00FF when I was running the program in RAM. I agree that the locations of the RAM and Stack can be changed. Do not see how the program would operate any differently if I did. -----Original Message----- From: [mailto:] Sent: Monday, February 24, 2003 7:36 PM To: Subject: Re: [m68HC11] Need debugging techniques on ADC to LCD In a message dated 2/24/03 9:45:58 PM Eastern Standard Time, writes: > Any and all ideas are welcome. > RAM EQU $0100 ;Beginning of RAM variables Code EQU $b600 ;Beginning of code area STACK EQU $0FFF ;put the stack at the top of the user RAM I looked at the ram and rom in the adapt11c24dx60... looks like its got 32k of rom from 0x8000 to 0xffff and 28k of external ram from 0x1000 to 0x7fff, E) processor has 512 bytes of internal ram 0x0000 to 0x01ff..... so right off the bat, I'd be setting RAM to 0x1000, Code to 0x8000, and STACK to 0x01ff (end of internal ram), ot 0x7fff (end of external ram). Whats this bit about the program goes in at 0xe000 and goes round and round and comes out here at 0xb600?? [Non-text portions of this message have been removed] To unsubscribe from this group, send an email to: |
|
I ran the program in a simulator (Shadow11) and it indeed got stuck in an endless loop. It seems like the problem is in your DELAY routine, shown here: DELAY ADDD TCNT ;determine desired value of TCNT DELAY1 CPD TCNT ;compare current TCNT with desired TCNT BLS DELAY1 ;wait until desired TCNT > current TCNT DELAY2 CPD TCNT ;compare current TCNT with desired TCNT BHI DELAY2 ;repeat until current TCNT > desired TCNT RTS ;done So, when D after the ADDD happens to become zero, the program can't get out the DELAY1 inner loop. That's because zero is always LOWER or SAME to any value, therefore, an endless loop! ----- Original Message ----- From: Nick Reitter, 3rd <> To: <> Sent: Tuesday, February 25, 2003 7:53 AM Subject: RE: [m68HC11] Need debugging techniques on ADC to LCD > I have tied the following pins high through a 10K resistor: IRQ, XIRQ, > RESET, STRB,STRB(R/W),E and AS. The program stops after a few minutes. I > still have to try the "dissecting" debugging technique suggested by Tony. > > Here is the code for displaying 6 voltages on the LCD............... > Nick |
|
|
|
Hello, The problem I had with the program "stopping" after a few minutes has been solved. I would like to thank everyone for your help. What finally did it, was revising the time delay that Tony mentioned. I have incorporated the final version of the program into this Email for anyone to use. It uses a 4x20 line LCD and displays 6 voltage readings, as volts ie. 4.46V. The program can be easily modified to change the volt reading to temperature or any other physical parameter depending on the sensor used. This ListServe is fantastic. A tremendous number of very knowledgeable and helpful people. Nick -----Original Message----- From: Tony Papadimitriou [mailto:] Sent: Tuesday, February 25, 2003 7:27 AM To: Subject: Re: [m68HC11] Need debugging techniques on ADC to LCD I ran the program in a simulator (Shadow11) and it indeed got stuck in an endless loop. It seems like the problem is in your DELAY routine, shown here: DELAY ADDD TCNT ;determine desired value of TCNT DELAY1 CPD TCNT ;compare current TCNT with desired TCNT BLS DELAY1 ;wait until desired TCNT > current TCNT DELAY2 CPD TCNT ;compare current TCNT with desired TCNT BHI DELAY2 ;repeat until current TCNT > desired TCNT RTS ;done So, when D after the ADDD happens to become zero, the program can't get out the DELAY1 inner loop. That's because zero is always LOWER or SAME to any value, therefore, an endless loop! * LCD6Volt.asm - February 26, 2003 *Adapt11C24DX60K *Six analog voltages will be displayed on the LCD using a decimal value *PE1,2,3,4,5,6; VRH should be = 5.12 Volts *Two programs were combined: Ex714_0.asm and LCDAd11a.asm * The LCD tested was a PWB 20434-CEM, OPTEX .(Purchased from ALL Electronics) * Display four rows of ASCII characters on a 20 X 4 LCD display * The display must be using a HD44780 or equivalent controller chip * Characters are copied from the 68HC11 memory area to DDRAM * Use the free-running counter TCNT for time delays * this program is based on these connections between the 68HC11 and the HD44780: * PB7 -- DB7 PB3 -- DB3 PA6 -- EN * PB6 -- DB6 PB2 -- DB2 PA5 -- R/W * PB5 -- DB5 PB1 -- DB1 PA4 -- RS * PB4 -- DB4 PB0 -- DB0 * ............................................................................ .. * Program Equates: * DDRAM addresses used by this display, bit 7 must be a 1 ADDR00 EQU %10000000 ;DDRAM address 00h ADDR40 EQU %11000000 ;DDRAM address 40h ADDR14 EQU %10010100 ;DDRAM address 14h ADDR54 EQU %11010100 ;DDRAM address 54h * Number of characters per logical line for this display NUMCHAR EQU 20 ;20 characters per logical line* *Memory allocations RAM EQU $0100 ;Beginning of RAM variables Code EQU $2000 ;Beginning of code area STACK EQU $0FFF ;put the stack at the top of the user RAM * HD44780 Instructions for this display and program RESET EQU %00110000 ;sent 3 times to reset display CLEAR EQU %00000001 ;clear display HOME EQU %00000010 ;return cursor to home position MODE EQU %00000110 ;shift cursor from left to right on read/write DISPOFF EQU %00001000 ;display off, cursor off, don't blink character SHIFT EQU %00010100 ;shift cursor to right without changing RAM FUNCT EQU %00111000 ;8 bit data, 4 line display, 5 x 7 font DISPON EQU %00001100 ;display on, cursor off, don't blink character * Control signals EN EQU %01000000 ;LCD Enable line RW EQU %00100000 ;LCD Read/Write line, 1 = write, 0 = read RS EQU %00010000 ;LCD Register Select line, 1 = character, 0 = instruction * Delay data (assuming a 2 MHz system clock) *Data changed for the new time delay subroutine *Not exact calculations **2222 is = to 10 milliseconds * System Equates: D40US EQU 10 ;data for 40 uSec overall time delay D100US EQU 22 ;data for 100 uSec overall time delay D1P6MS EQU 355 ;data for 1.6 mSec overall time delay D4P1MS EQU 1110 ;data for 4.1 mSec overall time delay D15MS EQU 3333 ;data for 15 mSec overall delay time D30MS EQU 65535 ;data for 30 mSec * REGBAS EQU $1000 ;base address of registers PORTA EQU $00 ;offset to I/O Port A PORTB EQU $04 ;offset to Output PORT B * *RAM allocation *$0100 RAM variables *$0FFF location of the top of stack *$2000 beginning of code RAM *Memory buffer ORG RAM DLYDTA RMB 4 ;storage for delay data FSN0 RMB 1 FSN RMB 1 ;First Significant Number SSN RMB 1 ;Second Significant Number TSN RMB 1 ;Third Significant Number TSNB RMB 1 BUFFER RMB 2 ;Temporary location for delay data * data area *Place in RAM --- * ASCII codes to be displayed, 4 lines X 20 characters * Must have 20 characters between 's *Program in Code memory ORG Code BRA Start ;leap over the embedded info FCB "4 voltages displayed on the LCD" Start: LDX #REGBAS BSET $39,X,$80 ;ADPU bit set to turn on A/D LDS #Stack ;Top of RAM for the stack *The ASCII code from LINE1, LINE2, LINE3 and LINE4 *is copied to RAM at location $0100 *These Lines are located at the very end of the program. *They are copied here for ease of seeing. *The x's are place holders *LINE1 FCC 'Voltages on Port E ' *LINE2 FCC 'PE1=x.xxV PE2=x.xxV' *LINE3 FCC 'PE3=x.xxV PE4=x.xxV' *LINE4 FCC 'PE5=x.xxV PE6=x.xxV' LDY #$0110 ;RAM location of Lines to be displayed LDX #LINE1 ;Source of ASCII information LDAB #80 ;4 lines x 20 characters Load: LDA 0,x ;Retrieve ASCII character to AccA STA 0,y ;PLace ASCII in RAM inx ;point to next ASCII char iny ;point to next RAM location DECB ;update counter BNE Load ;do it until all chars have been copied * reset and initialize the LCD controller chip JSR LCDINIT ;initialize the LCD Controller Chip for an 8-Bit interface *Analog Voltages are converted, converted to BCD then ASCII *************************************************** *PE1Volt Loop: LDAA #$21 ;A/D control word LDX #$0110+24 JSR Convert *************************************************** *PE2Volt LDAA #$22 ;A/D control word LDX #$0110+35 JSR Convert *************************************************** *PE3Volt: LDAA #$23 ;A/D control word LDX #$0110+44 JSR Convert *************************************************** *PE4Volt LDAA #$24 ;A/D control word LDX #$0110+55 JSR Convert ***************************************************** *PE5Volt: LDAA #$25 ;A/D control word LDX #$0110+64 JSR Convert *************************************************** *PE6Volt LDAA #$26 ;A/D control word LDX #$0110+75 JSR Convert ***************************************************** *The ASCII data in Line1, Line2, Line3 and Line4 is placed on the LCD * display the first group of ASCII characters stored in the 68HC11 memory LDX #LINE1 ;point to beginning of message to be displayed LDAA #ADDR00 ;point to initial DDRAM address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * display the next group of ASCII characters stored in the 68HC11 memory LDX #$0110+20 ;point to beginning of message to be displayed LDAA #ADDR40 ;increment address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * display the next group of ASCII characters stored in the 68HC11 memory LDX #$0110+40 ;point to beginning of message to be displayed LDAA #ADDR14 ;point to initial DDRAM address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * display the next group of ASCII characters stored in the 68HC11 memory LDX #$0110+60 ;point to beginning of message to be displayed LDAA #ADDR54 ;increment address LDAB #NUMCHAR ;initialize the character counter JSR DISPLY * Go back and repeat the cycle to display more voltages jmp Loop ************************************************************* * subroutines * this routine initialize the LCD Controller Chip for an 8-Bit interface LCDINIT PSHX ;preserve registers PSHB PSHA * set E, RS, and R/W low LDX #REGBAS ;point to base of I/O register block BCLR PORTA,X RS ;select the instruction register BCLR PORTA,X RW ;select the write mode BCLR PORTA,X EN ;clear the enable bit * initial 15 mS delay LDD #D15MS ;data for 15 mS delay JSR DELAY ;wait at least 4.1 mS * do a software reset by sending three Sequential Function Set instructions LDAA #RESET ;send first reset instruction JSR TOLCD ;write the instruction LDD #D4P1MS ;data for 4.1 mS delay JSR DELAY ;wait at least 4.1 mS LDAA #RESET ;send reset instruction again JSR TOLCD ;write the instruction LDD #D100US ;data for 100 uS delay JSR DELAY ;wait at least 100 uS LDAA #RESET ;send reset instruction a third time JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * controller initialization * Function Set instruction LDAA #FUNCT ;set 8-bit mode, display lines, font JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * Display On/Off Control instruction LDAA #DISPON ;display on, cursor off, don't blink JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * Clear Display instruction LDAA #CLEAR ;clear the display ram JSR TOLCD ;write the instruction LDD #D1P6MS ;data for 1.6 mS delay JSR DELAY ;wait at least 1.6 mS * Entry Mode Set instruction LDAA #MODE ;set the entry mode JSR TOLCD ;write the instruction LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS * Cursor to Home position LDAA #HOME ;cursor to home JSR TOLCD ;write the instruction LDD #D1P6MS ;data for 1.6 mS delay JSR DELAY ;wait at least 1.6 mS PULA ;restore registers PULB PULX RTS ;LCD Controller Chip initialization is complete * this routine copies data from EVB RAM to HD44780 DDRAM * enter with: (A) = first destination (DDRAM) address * (B) = number of characters to be displayed * (X) = address of first character in source string DISPLY PSHX ;preserve registers PSHY PSHB PSHA * prepare to send instructions LDY #REGBAS ;point to base of I/O register block BCLR PORTA,Y RS ;select the instruction register * set the DDRAM address JSR TOLCD ;write the instruction PSHA ;preserve DDRAM address PSHB ;preserve number of characters LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS PULB ;restore number of characters PULA ;restore DRAM address * prepare to send characters BSET PORTA,Y RS ;select the character register DISPLY1 LDAA $0,X ;get ASCII code from EVB RAM JSR TOLCD ;write the character PSHA ;save registers PSHB LDD #D40US ;data for 40 uS delay JSR DELAY ;wait at least 40 uS PULB ;restore registers PULA INX ;update message pointer DECB ;update the character counter BNE DISPLY1 ;continue until logical line is full PULA ;restore registers PULB PULY PULX RTS * this routine sends data to the LCD * enter with: (A) = the desired instruction or character * RW low * RS at the required level, 0 for instructions or 1 for characters TOLCD PSHX ;preserve registers LDX #REGBAS ;point to base of I/O register block STAA PORTB,X ;output the character NOP ;140 nSec delay BSET PORTA,X EN ;set the enable bit NOP ;450 nSec time delay BCLR PORTA,X EN ;clear the enable bit NOP ;remainder of 1000 nS Enable Cycle Time PULX ;restore registers RTS ;done * this routine is a general purpose hardware time delay using TCNT * arrive here with (D) = delay data (number of clock pulses for desired delay) * destroys (D) * Delay data (assuming a 2 MHz system clock) *Data changed for the new time delay subroutine *Not exact calculations *D40US EQU 10 ;data for 40 uSec overall time delay *D100US EQU 22 ;data for 100 uSec overall time delay *D1P6MS EQU 355 ;data for 1.6 mSec overall time delay *D4P1MS EQU 910 ;data for 4.1 mSec overall time delay *D15MS EQU 3333 ;data for 15 mSec overall delay time *D30MS EQU 65535 ;data for 30 mSec **2222 is = to 10 milliseconds DELAY: PSHX STD BUFFER ;D used instead of X,carry over from previous LDX BUFFER ;version of program Delay9: BEQ Finished ;decrement to zero DEX ;update delay data BRA Delay9 ;not 0, go back Finished:PULX RTS ****************************************************** *Accumulator A must contain the bit pattern for PEx, *the location showing where the voltage is connected Convert: STAA $1030 ;Initialize ADCTL register ;wait for conversion to be complete PSHX LDX #REGBAS Here BRCLR $30,x, $80, Here ;CCF flag musut be a 1 LDAA $1031 ;Read A/D register LDAB #$14 ;Load multiplier $14 (20dec) MUL ;Multiply (Input data) x $14 D LDX #10000 ;Load divisor 10,000 (2710hex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB FSN0 ;Store quotient in memory buffer XGDX ;Return remainder back to D LDX #1000 ;Load divisor 1,000 (3E8hex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB FSN ;Store quotient in memory buffer XGDX ;Return remainder back to D LDX #100 ;Load divisor 100 (64hex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB SSN ;Store quotient in memory buffer XGDX ;Return remainder back to D LDX #10 ;Load divisor 10 (Ahex) IDIV ;Integer divide XGDX ;Save remainder in X register STAB TSN ;Store quotient in memory buffer XGDX ;Return remainder back to D STAB TSNB ;Store quotient in memory buffer LDAA FSN ;Load first significant number ADDA #$30 ;Convert to ASCII PULX ;Retrieve location of Line# STA 0,X ;Place 1st significant number in LCD ram area LDAA SSN ;Load second value ADDA #$30 ;Convert to ASCII INX INX STA 0,X ;Place 2nd significant number in LCD ram area LDAA TSN ;Load third value ADDA #$30 ;Convert to ASCII INX STA 0,X ;Place 3rd significant number in LCD ram area RTS ************************************************************ ************************************************************ * ASCII codes to be displayed, 4 lines X 20 characters * Must have 20 characters between 's *The x's are place holders *These Lines are copied to RAM at $0100 LINE1 FCC 'Voltages on Port E ' LINE2 FCC 'PE1=x.xxV PE2=x.xxV' LINE3 FCC 'PE3=x.xxV PE4=x.xxV' |