搜尋此網誌

2013年1月29日 星期二

For ... To ... Next and Select ... Case ... End Select --> Excel VBA Examples


  Dim i As Integer 
  Dim rng As Range 
  For i = 1 To 4 
    Set rng = SetupRange(i) 
    Select Case i 
      Case 1 
        test_0 = 0
      Case 2 
        test_0 = 999
      Case 3 
        test_0 = 123
      Case 4 
        test_0 = 456
    End Select 
  Next i 

If ... Else ... End if --> Excel VBA Examples



If test_n <> 0 Then 'not equal
    a = 1
Else
    a = 0
End If


If test_n = 0 Then 'equal
    a = 1
Else
    a = 0
End If



If test_n > 0 & test_n <= 10 Then
    a = 1
Else
    a = 0
End If


2013年1月28日 星期一

Excel VBA改變區塊中的字型顏色(Green, Red, Black)


Sub Program0()

page_num = 2

Sheets(page_num).Range("H1") = Now()

   current_row = 1
   current_Col = 1
   If Sheets(page_num).Cells(current_row, current_Col + 1).Value > 0 Then
        Sheets(page_num).Cells(current_row, current_Col).Font.Color = -16776961 'Color Red
        Sheets(page_num).Cells(current_row, current_Col + 1).Font.Color = -16776961 'Color Red
   Else
        If Sheets(page_num).Cells(current_row, current_Col + 1).Value < 0 Then
            Sheets(page_num).Cells(current_row, current_Col).Font.Color = -11489280 'Color Green
            Sheets(page_num).Cells(current_row, current_Col + 1).Font.Color = -11489280 'Color Green
        Else
            Sheets(page_num).Cells(current_row, current_Col).Font.ColorIndex = xlAutomatic 'Color Black
            Sheets(page_num).Cells(current_row, current_Col + 1).Font.ColorIndex = xlAutomatic 'Color Black
        End If
   End If

For Each x In Sheets(page_num).Range("B4:B30")

   If x.Value > Sheets(page_num).Cells(x.Row, x.Column + 3).Value Then
        x.Font.Color = -16776961
   Else
        If x.Value < Sheets(page_num).Cells(x.Row, x.Column + 3).Value Then
            x.Font.Color = -11489280
        Else
            x.Font.ColorIndex = xlAutomatic
        End If
   End If
   
   change_num = 1
   Sheets(page_num).Cells(x.Row, x.Column + change_num).HorizontalAlignment = xlRight
   Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.ColorIndex = xlAutomatic
   If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value > 0 Then
        Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.Color = -16776961
   Else
        If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value < 0 Then
            Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.Color = -11489280
        End If
   End If
   
   change_num = 2
   Sheets(page_num).Cells(x.Row, x.Column + change_num).HorizontalAlignment = xlRight
   Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.ColorIndex = xlAutomatic
   If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value > 0 Then
        Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.Color = -16776961
   Else
        If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value < 0 Then
            Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.Color = -11489280
        End If
   End If
   
   change_num = 2
   If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value < 0.07 Then
       If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value < -0.07 Then
           For I = 2 To 13
               Sheets(page_num).Cells(x.Row, I).Font.Bold = True 'Enable Boldface
           Next I
       Else
           For I = 2 To 13
               Sheets(page_num).Cells(x.Row, I).Font.Bold = False 'Disable Boldface
           Next I
       End If
   Else
       For I = 2 To 13
           Sheets(page_num).Cells(x.Row, I).Font.Bold = True
       Next I
   End If
   
   x.Font.TintAndShade = 0
   For I = 0 To 4
       change_num = 7 + I
       If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value > Sheets(page_num).Cells(x.Row, x.Column + 3).Value Then
           Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.Color = -16776961
       Else
           If Sheets(page_num).Cells(x.Row, x.Column + change_num).Value < Sheets(page_num).Cells(x.Row, x.Column + 3).Value Then
               Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.Color = -11489280
           Else
               Sheets(page_num).Cells(x.Row, x.Column + change_num).Font.ColorIndex = xlAutomatic
           End If
       End If
   Next I
   
   Next
End Sub

2013年1月26日 星期六

Holtek MCU HT68F40(中文說明)

Holtek MCU HT68F40


Downloas Spec〈Click Here〉.

  • 功能說明

Part No. VDD Program Memory Data Memory Data EEPROM I/O Ext. Int. Timer Module Interface(SPI/I2C) UART Stack Package
HT68F40 2.2V~5.5V 4Kx15 192x8 12x8 22 2 10-bit CTM 1,
10-bit ETM 1,
16-bit STM 1
V X 8 24/28SKDIP/SOP/SSOP
44QFP, 32/40/48QFN
48SSOP


  • 腳位說明




  • I2C功能說明

開啟I2C功能,首先致能SIM函式在配制項目中,還有設定符合的位元在SIMCA、SIMC0與SIMC暫存器中。


  • I2C方塊圖







  • I2C暫存器表


為資料
  • SIMC0暫存器說明
Name:名稱
R/W:讀寫功能
POR:晶片預設值


Bit 7~5 SIM2, SIM1, SIM0: SIM Operating Mode Control
000: SPI主模式; SPI clock is fSYS/4
001: SPI主模式; SPI clock is fSYS/16
010: SPI主模式; SPI clock is fSYS/64
011: SPI主模式; SPI clock is fTBC
100: SPI主模式; SPI clock is TM0 CCRP match frequency/2
101: SPI從模式
110: 從模式
111: 未使用
These bits setup the overall operating mode of the SIM function. As well as selecting if the I2C or SPI function, they are used to control the SPI Master/Slave selection and the SPI Master clock frequency. The SPI clock is a function of the system clock but can also be chosen to be sourced from the TM0. If the SPI Slave Mode is selected then the clock will be supplied by an external Master device.

Bit 4 PCKEN: PCK 輸出腳位控制
0: 除能
1: 致能

Bit 3~2 PCKP1, PCKP0: 選擇PCK輸出腳位頻率
00: fSYS
01: fSYS/4
10: fSYS/8
11: TM0 CCRP match frequency/2

Bit 1 SIMEN: SIM控制
0: 除能
1: 致能
The bit is the overall on/off control for the SIM interface. When the SIMEN bit is cleared to zero to disable the SIM interface, the SDI, SDO, SCK and SCS, or SDA and SCL lines will be in a floating condition and the SIM operating current will be reduced to a minimum value. When the bit is high the SIM interface is enabled. The SIM configuration option must have first enabled the SIM interface for this bit to be effective. If the SIM is configured to operate as an SPI interface via the SIM2~SIM0 bits, the contents of the SPI control registers will remain at the previous settings when the SIMEN bit changes from low to high and should therefore be first initialised by the application program. If the SIM is configured to operate as an I2C interface via the SIM2~SIM0 bits and the SIMEN bit changes from low to high, the contents of the I2C control bits such as HTX and TXAK will remain at the previous settings and should therefore be first initialised by the application program while the relevant I2C flags such as HCF, HAAS, HBB, SRW and RXAK will be set to their default states.

Bit 0: 沒有定義此位元。
  • SIMC1暫存器說明
R:唯讀



Bit 7 HCF: I2C Bus資料傳輸完成旗標
0: 資料正在傳輸
1: 完成一個8位元的資料傳輸
The HCF flag is the data transfer flag. This flag will be zero when data is being transferred. Upon completion of an 8-bit data transfer the flag will go high and an interrupt will be generated.

Bit 6 HAAS: I2C匯流排位址相配旗標
0: 沒有位址相配
1: 發現位址相配
The HASS flag is the address match flag. This flag is used to determine if the slave device address is the same as the master transmit address. If the addresses match then this bit will be high, if there is no match then the flag will be low.

Bit 5 HBB: I2C匯流排忙碌旗標
0: I2C匯流排空閒中(可傳資料)
1: I2C匯流排忙碌中(不可傳資料)
The HBB flag is the I2C busy flag. This flag will be 1 when the I2C bus is busy which will occur when a START signal is detected. The flag will be set to 0 when the bus is free which will occur when a STOP signal is detected.

Bit 4 HTX: 選擇I2C從裝置為發送器或接收器
0: I2C從裝置為接收器
1: I2C從裝置為發送器

Bit 3 TXAK:I2C匯流排發送確認旗標
0: 從裝置發送確認旗標
1: 從裝置不發送確認旗標
The TXAK bit is the transmit acknowledge flag. After the slave device receipt of 8-bits of data, this bit will be transmitted to the bus on the 9th clock from the slave device. The slave device must always set TXAK bit to 0 before further data is received.

Bit 2 SRW: I2C從裝置讀/寫旗標
0: 從裝置應該是在接收模式
1:  從裝置應該是在傳送模式
The SRW flag is the I2C Slave Read/Write flag. This flag determines whether the master device wishes to transmit or receive data from the I2C bus. When the transmitted address and slave address is match, that is when the HAAS flag is set high, the slave device will check the SRW flag to determine whether it should be in transmit mode or receive mode. If the SRW flag is high, the master is requesting to read data from the bus, so the slave device should be in transmit mode. When the SRW flag is zero, the master will write data to the bus, therefore the slave device should be in receive mode to read this data.

Bit 1 IAMWU: I2C 位址匹配喚醒控制
0: 除能
1: 致能
這位元應該設定成1去致能 I2C 位址匹配喚醒,從睡眠或空閒模式。

Bit 0 RXAK: I2C匯流排接收確認旗標
0: 從裝置接收到確認旗標
1: 從裝置沒有接收到確認旗標
The RXAK flag is the receiver acknowledge flag. When the RXAK flag is 0 , it means that a acknowledge signal has been received at the 9th clock, after 8 bits of data have been transmitted. When the slave device in the transmit mode, the slave device checks the RXAK flag to determine if the master receiver wishes to receive the next byte. The slave transmitter will therefore continue sending out data until the RXAK flag is 1 . When this occurs, the slave transmitter will release the SDA line to allow the master to send a STOP signal to release the I2C Bus.


  • SIMD暫存器說明
x:可為0或1。
此為資料暫存器,讀寫資料將放置於此。

  • SIMA暫存器說明
 此為裝置暫存器,如果當主裝置時,從裝置位址將放置於此。當從裝置時,預被呼叫之位址將放置於此。

 Bit 7~1: (IICA6~ IICA0) I2C 主從位址。
IICA6~ IICA0 是此I2C從位址的位元6~ 位元0。
此SIMA暫存器也被用來當SPI介面,所以有另外一個名字叫SIMC2。 SIMA暫存器的7位元從裝置被定位(備儲存著7位元位址的從裝置)。SIMA的位元7〜1定義著從裝置的位址。位元0沒有被定義。
當主裝置,它是被連接到I2C的匯流排。當它發送一個地址到相匹配的從裝置位址的SIMA暫存器中,其從裝置將被選中。需要注意的是:SIMA暫存器與SPI介面SIMC2的暫存器是相樣的暫存器地址。

Bit 0: 沒有定義此位元。
  • 組合語言指令集
Mnemonic
Description
Cycles
Flag Affected
Arithmetic
(計算)


ADD A,[m]
ADDM A,[m]
ADD A,x
ADC A,[m]
ADCM A,[m]
SUB A,x
SUB A,[m]
SUBM A,[m]
SBC A,[m]
SBCM A,[m]
DAA [m]
Add Data Memory to ACC
Add ACC to Data Memory
Add immediate data to ACC
Add Data Memory to ACC with Carry
Add ACC to Data memory with Carry
Subtract immediate data from the ACC
Subtract Data Memory from ACC
Subtract Data Memory from ACC with result in Data Memory
Subtract Data Memory from ACC with Carry
Subtract Data Memory from ACC with Carry, result in Data Memory
Decimal adjust ACC for Addition with result in Data Memory
1
1Note
1
1
1Note
1
1
1Note
1
1Note
1Note
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
C
Logic Operation
(邏輯運算)

AND A,[m]
OR A,[m]
XOR A,[m]
ANDM A,[m]
ORM A,[m]
XORM A,[m]
AND A,x
OR A,x
XOR A,x
CPL [m]
CPLA [m]
Logical AND Data Memory to ACC
Logical OR Data Memory to ACC
Logical XOR Data Memory to ACC
Logical AND ACC to Data Memory
Logical OR ACC to Data Memory
Logical XOR ACC to Data Memory
Logical AND immediate Data to ACC
Logical OR immediate Data to ACC
Logical XOR immediate Data to ACC
Complement Data Memory
Complement Data Memory with result in ACC
1
1
1
1Note
1Note
1Note
1
1
1
1Note
1
Z
Z
Z
Z
Z
Z
Z
Z
Z
Z
Z
Increment & Decrement
(增加&減少)

INCA [m]
INC [m]
DECA [m]
DEC [m]
Increment Data Memory with result in ACC
Increment Data Memory
Decrement Data Memory with result in ACC
Decrement Data Memory
1
1Note
1
1Note
Z
Z
Z
Z
Rotate
(旋轉)

RRA [m]
RR [m]
RRCA [m]
RRC [m]
RLA [m]
RL [m]
RLCA [m]
RLC [m]
Rotate Data Memory right with result in ACC
Rotate Data Memory right
Rotate Data Memory right through Carry with result in ACC
Rotate Data Memory right through Carry
Rotate Data Memory left with result in ACC
Rotate Data Memory left
Rotate Data Memory left through Carry with result in ACC
Rotate Data Memory left through Carry
1
1Note
1
1Note
1
1Note
1
1Note
None
None
C
C
None
None
C
C
Data Move
(資料搬移)

MOV A,[m]
MOV [m],A
MOV A,x
Move Data Memory to ACC
Move ACC to Data Memory
Move immediate data to ACC
1
1Note
1
None
None
None
Bit Operation
(位元運算)

CLR [m].i
SET [m].i
Clear bit of Data Memory
Set bit of Data Memory
1Note
1Note
None
None
Branch
(分支)

JMP addr
SZ [m]
SZA [m]
SZ [m].i
SNZ [m].i
SIZ [m]
SDZ [m]
SIZA [m]
SDZA [m]
CALL addr
RET
RET A,x
RETI
Jump unconditionally
Skip if Data Memory is zero
Skip if Data Memory is zero with data movement to ACC
Skip if bit i of Data Memory is zero
Skip if bit i of Data Memory is not zero
Skip if increment Data Memory is zero
Skip if decrement Data Memory is zero
Skip if increment Data Memory is zero with result in ACC
Skip if decrement Data Memory is zero with result in ACC
Subroutine call
Return from subroutine
Return from subroutine and load immediate data to ACC
Return from interrupt
2
1Note
1note
1Note
1Note
1Note
1Note
1Note
1Note
2
2
2
2
None
None
None
None
None
None
None
None
None
None
None
None
None
Table Read
(表格讀取)

TABRD [m]
TABRDL [m]
Read table to TBLH and Data Memory
Read table (last page) to TBLH and Data Memory
2note
2Note
None
None
Miscellaneous
(各式各樣的)

NOP
CLR [m]
SET [m]
CLR WDT
CLR WDT1
CLR WDT2
SWAP [m]
SWAPA [m]
HALT
No operation
Clear Data Memory
Set Data Memory
Clear Watchdog Timer
Pre-clear Watchdog Timer
Pre-clear Watchdog Timer
Swap nibbles of Data Memory
Swap nibbles of Data Memory with result in ACC
Enter power down mode
1
1Note
1Note
1
1
1
1Note
1
1
None
None
None
TO, PDF
TO, PDF
TO, PDF
None
None
TO, PDF

  • 相關文件

http://www.holtek.com.tw/english/tech/appnote/appnote.htm#mcu






2013年1月25日 星期五

在Mac下,如何進入UEFI模式

在Mac平台下的UEFI並不是一個圖形管理的介面,一般是只有一個命令列,如:Shell〉。開機時,透過的組合鍵或是熱鍵來進入功能設定介面。一般來說不太需要修改設定,因為它本身就是最佳化設置。

你可以在Mac開機時,按住如下的組合鍵,去進入其功能設定:
  1. 按住〈C〉,從CD 或DVD 光碟機啟動,如:Mac OS X 安裝光碟。
  2. 按住〈D〉,如果插入安裝DVD 1,則啟動為Apple Hardware Test (AHT)。
  3. 按住〈Option〉+〈Command〉+〈PR〉 ,直到聽到兩聲BB聲-->Reset NVRAM。
  4. 按住〈Option〉 ,開機後進入Startup Manager,你可以在這些選項中,選擇從一個你想的Mac OS X 項目去開機。注意:按住〈N〉 鍵,可顯示出第一個可啟動的網絡選項。你也可以選擇從UEFI磁碟作開機,去做一些內部設定。
  5. 按住〈Eject〉or〈F12〉 ,或者按住鼠標鍵(/觸控板),退出所有可移動的媒體,如光碟,USB。
  6. 按住〈N〉,試著從相容的網絡伺服器(NetBoot)去作開機的動作。
  7. 按住〈T〉,開機後成為FireWire 目標(Taget)的磁碟模式。
  8. 按住〈Shift〉,開機後成為安全模式,並且暫時關閉登錄選項。
  9. 按住〈Command〉+〈V〉,開機後成為Verbose 模式。
  10. 按住〈Command〉+〈S〉,開機後成為單一使用者模式。
  11. 按住〈Option〉+〈N〉,使用系統預設執的開機鏡像,從NetBoot伺服器開機。

2013年1月20日 星期日

Check HD whether it has support Staggered Spin-Up(Pin11 of SATA Power Connectot)

Pin 11 can function for staggered spinup, activity indication, both, or nothing. It is an open collector signal, that may be pulled down by the connector or the drive. If pulled down at the connector (as it is on most cable-style SATA power connectors), the drive spins up as soon as power is applied. If left floating, the drive waits until it is spoken to, This prevents many drives from spinning up simultaneously, which might draw too much power. The pin is also pulled low by the drive to indicate drive activity. This may be used to give feedback to the user through an LED.
接地("0")時,HDD動作。浮接(空接)時,HDD等待Controller信號驅動。不是每一種HDD都可以支援。

SATA Power Connector
Pin #MatingFunction
 —Coding notch
13rd3.3 V
23rd
32nd
41stGround
52nd
62nd
72nd5 V
83rd
93rd
102ndGround
113rdStaggered spinup/activity
(in supporting drives)
121stGround
132nd12 V
143rd
153rd

SATA DATA Connector
Pin #MatingFunction
11stGround
22ndA+ (Transmit)
32ndA− (Transmit)
41stGround
52ndB− (Receive)
62ndB+ (Receive)
71stGround
 —Coding notch

WD有幾款硬碟有支援ATA Command Base去喚醒它,可以把預設置設成電源關閉(Power Up in Standby)。

Staggered Spin-Up supported HDD list:

http://highpoint-tech.com/PDF/RR23xx/RR23xx_Compatibility_List.pdf

Effectively there have been 3 attempts by the standards to initiate Staggered Spin:

  1. Original – Drive would not spin until PHY Ready was achieved.  That was not really followed and has gone by the wayside with Microsoft requirements for power to boot time for Windows systems.
  2. P11 - If a drive implements P11 then the drive relies on the host to manage the state of P11 to enable/disable the drive to spin on power.  If P11 is set to enable DSS then the drive will not spin until PHY Ready is achieved.
  3. PUIS – Power In Standby – If PUIS is enabled the drive will power up and remain in spun down state until the drive receives a Set Feature command instructing the drive to spin or until the drive receives a command that requires media access.