83:Ports:04

From WikiTI
Jump to: navigation, search

Synopsis

Port Number: 04h

Function: Timer Interrupt Frequency, Memory Map Control and Battery Status Checking

This port controls the frequency of the hardware timer and the memory map mode. The higher bits of this port control at which voltage level bit 0 of port 14 flips.

Read Values

This is a mirror of the link port.

Write Values

  • Bit 0 controls the memory mapping mode. The default value for this bit is 0.
  • Bits 1 and 2 control the hardware timer frequency. Setting both 0 sets the timer to the fastest speed, and both 1 is the slowest speed. The default is with both bits 1.
  • Bit 3: Unused? Always 0.
  • Bit 4: Timer frequency multiplier; when this bit is set, all the times are multiplied by 90% (i. e. it's 11.1% faster) compared to when it's reset.
  • Bit 5: Set this bit to keep the reset circuit high even when bit 0 of port 14 is 0. The default value for this bit is 0.
  • Bits 6-7: These bits control the voltage level you want to compare the batteries with. After changing these bits you need a delay for port 14 to adapt. A 100 clock cycles should be more than sufficient. The default value for these bits is 00.
    • 00: Bit 0 of port 14 will go low when voltage drops below ~3.2V and high again when over ~3.5V.
    • 10: Bit 0 of port 14 will go low when voltage drops below ~3.5V and high again when over ~3.8V.
    • 01: Bit 0 of port 14 will go low when voltage drops below ~3.8V and high again when over ~4.2V. This test is continuously used by the OS to safe power down when necessary.
    • 11: Bit 0 of port 14 will go low when voltage drops below ~4.2V and high again when over ~4.6V. This test is used when you turn the calculator on to display a low battery warning when necessary.

Comments

  • The voltages given above are purely indicative and may be highly inaccurate. (until somebody confirms them)
  • To calculate the resulting timer frequency you can use the following formula:
freq = 1800 * ((out_value & 0x10) ? 1.0 : 0.9) / (3 + ((out_value & 0x06) << 1))

Example

This example shows how to test the batteries.

 ld a,36h   ;First we make sure the calculator doesn't reset
 out (4),a  ;when we change bits 6 and 7.
 ld a,76h   ;We'll check if batteries are below ~3.8V.
 out (4),a
 ld b,8     ;After changing bits 6 and 7 we need a delay.
 djnz $
 in a,(14h) ;Read the battery status
 ld c,a     ;and save it.
 ld a,36h   ;Set bits 6 and 7 back to default but keep bit 5
 out (4),a  ;set until after the delay.
 ld b,8     ;After changing bits 6 and 7 we need a delay.
 djnz $
 ld a,16h   ;Now it's safe to reset bit 5 too.
 out (4),a
 bit 0,c    ;Bit 0 is zero when batteries are lower than ~3.8V.