Here I'm again.
Again to my last post:
I think over it again and C Flag is also an System Variable.
Also too unsuitable.
What have I done:
I rewrite the code once again.
I change the Variable Name's an insert your code from Statement 2.
Could it be, that there is an small mistake.
Once Again here is the codeCode:F var byte G var byte ;D = B >> E F = E G = B ShiftLoop ;G = G >> 1 G = G << 1 F = F - 1 IF F != 0 THEN ShiftLoop ;D = G.0 D = G.7
I also wanted to replace the For To Loop with an normal If - Then request, because of the Usage of System Variables; or is there neither.Code:Char_Temp var byte ShiftOut_Steps var byte Count_ShiftOut_Steps var byte ShiftLoop_Steps Var byte Bit_Shift Var byte Readout_Bit var bit INCLUDE "VirtualPort.bas" LCD_DATAUS CON 2000 LCD_COMMANDUS CON 50 Goto Over_One_Wire_74HC595 ;===============( DO NOT Change anything below this line )==================== ASM ; Make sure HighJack has been installed in PBP's .LIB file ifndef LCDOUT_HIGHJACKED error "HighJacked-LCDOUT Not found in PBPPIC??.LIB" endif ENDASM DEFINE HJ_LCDOUT _LCDsend ; Redirect PBP's LCDOUT to LCDsend: Subroutine ;----[Send a byte to the Virtual LCD PORT]------------(DO NOT Change)--------- TempChar var byte Char VAR Byte LCD_Initialized VAR FLAGS.1 RSS VAR FLAGS.0 ; LCD RS State ;----[ This routine is called once for every character sent by LCDOUT ]------- LCDsend: @ MOVE?AB _TempChar ; Get char sent by LCDOUT, in WREG if !LCD_Initialized then LCD_Init ; Make sure LCD was Initialized LCDAfterInit: if TempChar = $FE then RSS=0 : goto LCDsendDone ; next char is Command Char = TempChar LCDsendCOM: Goto ShiftLoop_Char After_ShiftLoop_Char: IF RSS = 0 then ; Is a Command IF Char = 1 then CommandDelay ; Long delay for Clear Screen IF Char = 2 then CommandDelay ; Long delay for Home @ DelayUS _LCD_DATAUS ; Short delay for everything else goto DelayDone else @ DelayUS _LCD_DATAUS ; Short delay for Data goto DelayDone endif CommandDelay: @ DelayUS _LCD_COMMANDUS DelayDone: if LCD_Initialized then RSS = 1 ; Set RS to Data next time LCDsendDone: return ;----[Initialize the LCD]-------------------(DO NOT Change)------------------- LCD_Init: ShiftOut_Steps = 2 Char = $33 : gosub LCDsendCOM : @ DelayUS 5000 gosub LCDsendCOM : @ DelayUS 100 gosub LCDsendCOM : @ DelayUS 100 Char = $22 : gosub LCDsendCOM ; Start 4-bit mode ShiftOut_Steps = 5 Char = $28 : gosub LCDsendCOM ; Function Set, 4-bit, 2-line, 5x7 Char = $0C : gosub LCDsendCOM ; Display ON Char = $06 : gosub LCDsendCOM ; Entry Mode LCD_Initialized = 1 ; LCD has been Initialized goto LCDAfterInit ;----[Send it to 74HC595]-------------------(DO NOT Change)------------------- ShiftLoop_Char: For Count_ShiftOut_Steps = 0 to ShiftOut_Steps ' For To Loop SELECT CASE Count_ShiftOut_Steps CASE 0 Char_Temp = Char & %11110000 ; Isolate Upper 4 Bits If RSS = 1 Then : Char_Temp = Char_Temp | %00000100 ; Set RS Bit CASE 1, 4 Char_Temp = Char_Temp | %00001000 ; Set Enable Bit CASE 2, 5 Char_Temp = Char_Temp ^ %00001000 ; Toggel Enable Case 3 Char_Temp = Char << 1 ; Shift Up Lower 4 Bits Char_Temp = Char_Temp << 1 Char_Temp = Char_Temp << 1 Char_Temp = Char_Temp << 1 If RSS = 1 Then : Char_Temp = Char_Temp | %00000100 ; Set RS Bit END SELECT Bit_Shift = Char_Temp ;----[Shift_Routine_74HC595 ]---------------(DO NOT Change)------------------- ShiftLoop_Steps = 7 ShiftLoop: Readout_Bit = Bit_Shift.7 SELECT CASE Readout_Bit CASE 1 Serial_Pin = 0 : @ DelayUS 1 ; min 1 µs for 1 Serial_Pin = 1 : @ DelayUS 15 ; min 15 µs Case 0 Serial_Pin = 0 : @ DelayUS 15 ; min 15 µs for 0 Serial_Pin = 1 : @ DelayUS 30 ; min 30 µs END SELECT Bit_Shift = Bit_Shift << 1 ShiftLoop_Steps = ShiftLoop_Steps - 1 IF ShiftLoop_Steps != 0 THEN : Goto ShiftLoop ;Latch Serial_Pin = 0 : @ DelayUS 200 ; min 200 µs for Latch Serial_Pin = 1 : @ DelayUS 300 ; min 300 µs 'Count_ShiftOut_Steps = Count_ShiftOut_Steps + 1 ' for If Then Request 'IF Count_ShiftOut_Steps != ShiftOut_Steps Then : goto ShiftLoop_Char ' for If Then Request Next ' For To Loop Goto After_ShiftLoop_Char Over_One_Wire_74HC595:
It also works well but when I simulate it, it takes too much CPU Usage and Runs very slow.
Using an Repeat Until Loop also.
With an For To Loop the simulation is better.
But which Loop is the best, when one think only about the Usage in an Microcontroller?
What did you say. Is it OK or is there something which one can also improve.
Thanks in advance!




Bookmarks