控制DS1804采用8051兼容微控制器-Controlli
[09-13 17:04:14] 来源:http://www.88dzw.com 控制技术 阅读:8106次
文章摘要:Main Program OutputAssume that you are executing the program with VCC at 5V with a 22 MHz crystal; a multi-meter is connected between W and Gnd; and cycling VCC from Gnd to 5V starts the program. The output of the DS1804 will be as follows.When power is turned on, the part will boot up to the value
控制DS1804采用8051兼容微控制器-Controlli,标签:计算机控制技术,工厂电气控制技术,http://www.88dzw.comMain Program Output
Assume that you are executing the program with VCC at 5V with a 22 MHz crystal; a multi-meter is connected between W and Gnd; and cycling VCC from Gnd to 5V starts the program. The output of the DS1804 will be as follows.When power is turned on, the part will boot up to the value last stored in the NV register. If the value of the NV register was previously written, then it will display that value; otherwise it will display the pseudo-random value stored in the NV register by the factory before shipping. The wiper output will display the voltage on the multi-meter that corresponds to the value stored in the NV register for 3 seconds. The output will then be incremented in 0.25V steps and hold each value for 3 seconds before moving on to the next position. This will occur five times for a total voltage change of 1.25V. The wiper voltage will then be lowered 0.25V, and that value will be held for 3 seconds. This value will be stored in the NV register and will be the value that the part boots up to the next time power is cycled. Finally, the wiper voltage will be incremented 0.05V and then decremented 0.05V, with both values being held for 3 seconds. The LED attached to P1.0 will be toggled every 3 seconds directly before every change occurs.
In the event that the chip powers up with a wiper value equal to or greater than 3.76V, the program will attempt to increment the chip past 5V. This does not damage the part, but the output will remain at 5V until a decrement command is issued. Thus the end voltage in this case would be 4.75V.
Appendix A—8051 Software Used to Communicate with the DS1804
;********************************************************************* ;* DS87C520 APPS DEVELOMENT SYSTEM * ;* * ;* Application: Communication with a DS1804 * ;********************************************************************* ;* * ;* Software Revision History * ;* * ;* 1.0 02/07/01 - First try at operating a DS1804 using the * ;* generic application engineering generic 8051 * ;* boot loading board. * ;* * ;* Hardware Description * ;* * ;* P1.0 - LED P0.0 - SN74F373N * ;* P1.1 - P0.1 - " * ;* P1.2 - RXD1 - Not used P0.2 - " * ;* P1.3 - TXD1 - Not used P0.3 - " * ;* P1.4 - nInc P0.4 - " * ;* P1.5 - UnD P0.5 - " * ;* P1.6 - nCS P0.6 - " * ;* P1.7 - P0.7 - " * ;* * ;* P3.0 - RXD0 - Not used P2.0 - Upper * ;* P3.1 - TXD0 - Not used P2.1 - Address * ;* P3.2 - P2.2 - Byte * ;* P3.3 - P2.3 - " * ;* P3.4 - P2.4 - " * ;* P3.5 - P2.5 - " * ;* P3.6 - WR\ P2.6 - " * ;* P3.7 - RD\ P2.7 - " * ;* * ;* Window 0 R0 - Used as scratch pad, destroy with caution! * ;* Window 0 R5-R7 Used for timer/scratch pad, destroy with caution! * ;********************************************************************* $include (c:\firmware\reg520.inc) ; SFR register defs for compiler ;************* Variable Declarations ************* ;** General Variables ** stack equ 02Fh ; bottom of stack ; stack starts at 30h ;************* SFR Declarations ************* ;** General SFR Names ** smod_1 equ 0DFh ; buad rate doubler bit declared ;** Port 1 Signal Names ** LED equ 90h ; P1.0 is LED ; P1.1 is not used RX1 equ 92h ; P1.2 is Serial Port 1 RX TX1 equ 93h ; P1.3 is Serial Port 1 TX nInc equ 94h ; P1.4 is not Inc, - 1804 UnD equ 95h ; P1.5 is Up not Down - 1804 nCS equ 96h ; P1.6 is not ChipSelect - 1804 ; P1.7 is not used ;********************************************************************* ;* Hardware Interrupt Vectors (Table on page 95 of DS databook) * ;********************************************************************* ;* No Interrupts are enabled in this code. If interrupts are to be * ;* enabled they need to have the label initialized here. * ;********************************************************************* org 0000h ; Power up and Reset ljmp start org 0003h ; External Interrupt 0 ljmp start org 000Bh ; Timer 0 Interrupt ljmp start org 0013h ; External Interrupt 1 ljmp start org 001Bh ; Timer 1 Interrupt ljmp start org 0023h ; Serial Port 0 Interrupt ljmp start org 002Bh ; Timer 2 Interrupt ljmp start org 0033h ; PowerFail Interrupt (DS Priority 1) ljmp start org 003Bh ; Serial Port 1 Interrupt (DALLAS) ljmp start org 0043h ; External Interrupt 2 (DALLAS) ljmp start org 004Bh ; External Interrupt 3 (DALLAS) ljmp start org 0053h ; External Interrupt 4 (DALLAS) ljmp start org 005Bh ; External Interrupt 5 (DALLAS) ljmp start org 0063h ; Watchdog Interrupt (DALLAS) ljmp start org 006Bh ; Real-Time Clock (DALLAS) ljmp start ;********************************************************************* ;**** The Main Program demonstrates using a 8051 to communicate **** ;**** with a DS1804. The program increments and decrements the **** ;**** potentiometer without writing the NV Register, and it **** ;**** demonstrates writing to the NV Register as well. **** ;********************************************************************* org 0080h ; location that hardware begins execution start: ; after a reset. clr EA ; Disable Interrupts cpl LED ; Complement LED - Identifies that the ; program has started execution lcall init1804 ; initializes DS1804, must be done in first ; 50ms to avoid the three inputs becoming ; active without them being in a known ; state. lcall wait3sec ; give time to read the last NVReg value ; on a multimeter cpl LED ; toggle LED mov R0, #5 ; increment the 1804 by 5 intervals, 5 times, loop10: ; with 3 seconds between increments lcall Increment1804x5 ; increment the DS1804 lcall wait3sec ; waits 3 seconds cpl LED ; toggle LED djnz R0, loop10 lcall Decrement1804x5 ; decrement the 1804 5 intervals cpl LED ; toggle LED lcall WriteNVreg ; write current value to NVReg. Now 20 steps ; greater that the start of execution. lcall wait3sec ; wait 3 seconds for multimeter use cpl LED ; complement LED lcall Increment1804 ; increment 1804 once, don't write NVReg lcall wait3sec ; wait 3 seconds for multimeter use cpl LED ; Complement LED lcall Decrement1804 ; decrement 1804 once, don't write NVReg lcall wait3sec ; wait 3 seconds for multimeter use cpl LED ; Complement LED EndOfMain: ; wait forever sjmp EndOfMain ;********************************************************************* ;**** Increment DS1804x5 Routine **** ;**** Increments the chip 5 times without de-selecting the **** ;**** the chip between increments. This does not write to the **** ;**** nonvolatile register. **** ;********************************************************************* ;* Uses no other routines, and destroys no registers * ;********************************************************************* Increment1804x5: setb UnD ; select increment clr nCS ; select chip clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nCS ; set nCS before nInc to avoid writing to ; the NV EEPROM register in the DS1804 setb nInc ; set nInc back to inactive state. ret ;********************************************************************* ;**** Increment DS1804 Routine **** ;**** Increments the chip 1 time, and de-selects the chip **** ;**** without writing to the nonvolatile register. **** ;********************************************************************* ;* Uses no other routines, and destroys no registers * ;********************************************************************* Increment1804: setb UnD ; select increment clr nCS ; select chip clr nInc ; clear inc - increase to next position setb nCS ; set nCS before nInc to avoid writing to ; the NV EEPROM register in the DS1804 setb nInc ; set nInc back to inactive state. ret ;********************************************************************* ;**** Decrement DS1804x5 Routine **** ;**** Decrements the chip 5 times without de-selecting the **** ;**** the chip between decrements. This does not write to the **** ;**** nonvolatile register. **** ;********************************************************************* ;* Uses no other routines, and destroys no registers * ;********************************************************************* Decrement1804x5: clr UnD ; select increment clr nCS ; select chip clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nInc ; set nInc back to inactive state. clr nInc ; clear inc - increase to next position setb nCS ; set nCS before nInc to avoid writing to ; the NV EEPROM register in the DS1804 setb nInc ; set nInc back to inactive state. ret ;********************************************************************* ;**** Decrement DS1804 Routine **** ;**** Decrements the chip 1 time, and de-selects the chip **** ;**** without writing to the nonvolatile register. **** ;********************************************************************* ;* Uses no other routines, and destroys no registers * ;********************************************************************* Decrement1804: clr UnD ; select decrement clr nCS ; select chip clr nInc ; clear inc - decrease to next position setb nCS ; set nCS before nInc to avoid writing to ; the NV EEPROM register in the DS1804 setb nInc ; set nInc back to inactive state. ret ;********************************************************************* ;**** DS1804 Write Nonvolatile Register Routine **** ;**** Writes the Nonvolatile Register to the current wiper **** ;**** value, and then waits 10ms for the write to occur. **** ;********************************************************************* ;* Uses wt routine, and destroys registers R5, R6, and R7 * ;********************************************************************* WriteNVreg: clr nCS ; select chip setb nCS ; deselect chip, nInc already high so the ; DS1804 will store to the NV Register mov R5, #255 ; wait 10ms before continuing, the NV Reg. mov R6, #3 ; storage time mov R7, #1 ; lcall wt ; ret ;********************************************************************* ;**** Initialize DS1804 Routine **** ;**** Sets all three control signals to their inactive state, **** ;**** and waits 50ms for the inputs to become active before **** ;**** returning to the main program. **** ;********************************************************************* ;* Uses wt routine, and destroys registers R5, R6, and R7 * ;********************************************************************* init1804: setb nCS ; de-select 1804 setb nInc ; de-activate Increment Signal setb UnD ; select increment mov R5, #255 ; wait 50ms, this is done so communication mov R6, #15 ; will not begin before the DS1804 is ready mov R7, #1 ; to accept input. lcall wt ; ret ;********************************************************************* ;**** Wait 3 Seconds Function **** ;********************************************************************* ;* requires wt routine, and destroys R5, R6 and R7 * ;********************************************************************* wait3sec: mov R5, #255 ; wait 3 sec., this is done so advances can mov R6, #147 ; be watched on a multi-meter mov R7, #6 ; lcall wt ; ret ;********************************************************************* ;**** General Wait Function **** ;**** Can wait anywhere between 14.42us to 221 sec. **** ;**** Waits R7 * 867.6 ms if R5 = R6 = 255 **** ;**** Waits R6 * 3.4 ms if R5 = 255 and R7 = 1 **** ;**** Waits R5 * 13.34us if R6 = R7 = 1 **** ;********************************************************************* ;* requires wait16us routine * ;* destroys R5, R6, and R7 registers * ;********************************************************************* wt: lcall wait16us ; 12.8us of waits lcall wait16us lcall wait16us lcall wait16us lcall wait16us lcall wait16us lcall wait16us lcall wait16us djnz R5, wt ;Wait = R5 * 13.34us + 1.1us if R6 = R7 = 1 djnz R6, wt ;Wait = R6 * 3.4ms if R5 = 255, R7 = 1 djnz R7, wt ;Wait = R7 * 867.6ms if R5 = R6 = 255 ret ;********************************************************************* ;**** Wait 1.6 us Function **** ;**** Wastes 1.6us of processor time with call, nop and return **** ;********************************************************************* ;* Requires no other routines or registers * ;********************************************************************* wait16us: nop ; 1 nops @4cc each + lcall @16cc + ret @16cc ; produces approximately 1.6us of delay with a ; 22.22MHz clock ret END ;End of program
Tag:控制技术,计算机控制技术,工厂电气控制技术,控制技术
《控制DS1804采用8051兼容微控制器-Controlli》相关文章
- › 控制DS1804采用8051兼容微控制器-Controlli
- 在百度中搜索相关文章:控制DS1804采用8051兼容微控制器-Controlli
- 在谷歌中搜索相关文章:控制DS1804采用8051兼容微控制器-Controlli
- 在soso中搜索相关文章:控制DS1804采用8051兼容微控制器-Controlli
- 在搜狗中搜索相关文章:控制DS1804采用8051兼容微控制器-Controlli
分类导航
最新更新