Tracid
Member level 3
- Joined
- Nov 1, 2006
- Messages
- 57
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,288
- Location
- Neded, Slovakia
- Activity points
- 1,756
Hello
It was 4 years ago when i last worked with PIC16F84A and that was only a few lessons in school. Yesterday my brother asked me to write a code to control some sort of machine. I managed to write the code and simulate it by using LEDs on outputs. The aim is to control four electromagnets and code time for they should be turned on. This is now at test phase and it is 2seconds (routine generated by online delay generator found on internet)
Here comes the hardest part for me as i was not working with PICs only a few times: we do not know how long the electromagntets should be energised so we decided to use pushbuttons to adjust time. The actual routine in ASM looks like this:
Delay
;1999996 cycles
movlw d'17'
movwf twosec_d1
movlw d'93'
movwf twosec_d2
movlw d'5'
movwf twosec_d3
Delay_0
decfsz twosec_d1, f
goto $+2
decfsz twosec_d2, f
goto $+2
decfsz twosec_d3, f
goto Delay_0
;4 cycles (including call)
return
this is only for fixed time(2sec). We want the time to be adjustable between 1-4secs in say 50msec steps using 4MHz crystal. In this routine it would be difficult for me since i had to insert one more variable and calculate which to modify to which value.... Could anybody recommend me a simple routine or idea how to make delay adjustable by pushbuttons (up down) between 1sec and 4secs? PIC16F84A, 4MHz, ASM code
thank you )
Added after 2 minutes:
sorry for the unsorted code, i just copy pasted it and it got unsorted
Added after 1 hours 44 minutes:
the code doesnt need to be optimised, i do not need much space for the remaining code...
It was 4 years ago when i last worked with PIC16F84A and that was only a few lessons in school. Yesterday my brother asked me to write a code to control some sort of machine. I managed to write the code and simulate it by using LEDs on outputs. The aim is to control four electromagnets and code time for they should be turned on. This is now at test phase and it is 2seconds (routine generated by online delay generator found on internet)
Here comes the hardest part for me as i was not working with PICs only a few times: we do not know how long the electromagntets should be energised so we decided to use pushbuttons to adjust time. The actual routine in ASM looks like this:
Delay
;1999996 cycles
movlw d'17'
movwf twosec_d1
movlw d'93'
movwf twosec_d2
movlw d'5'
movwf twosec_d3
Delay_0
decfsz twosec_d1, f
goto $+2
decfsz twosec_d2, f
goto $+2
decfsz twosec_d3, f
goto Delay_0
;4 cycles (including call)
return
this is only for fixed time(2sec). We want the time to be adjustable between 1-4secs in say 50msec steps using 4MHz crystal. In this routine it would be difficult for me since i had to insert one more variable and calculate which to modify to which value.... Could anybody recommend me a simple routine or idea how to make delay adjustable by pushbuttons (up down) between 1sec and 4secs? PIC16F84A, 4MHz, ASM code
thank you )
Added after 2 minutes:
sorry for the unsorted code, i just copy pasted it and it got unsorted
Added after 1 hours 44 minutes:
the code doesnt need to be optimised, i do not need much space for the remaining code...