Home > Something else > Here

Tip's & Trick's...


***********************************************************

change a Pot lin. <--> log.

***********************************************************
register swapping :

with Buffer : c=a / a=b / b=c - this swap the Reg. a <-> b - Buffer is 'c'
---------------------
with EXOR :
a = a^b
b = a^b
a = a^b
then a^b^a = b | ^ is bitwise EXOR
When in Reg.A the result of a EXOR linkup of two Var. ,and we now one of the Var.'s , we can recombined .
This is a thing most Kryptologic systems use.

***********************************************************
Increment a loopcounter with Z-reg. | on devices with the addiw Instruction you write :

adiw zlo,1

but what goes on when (Atiny15) don't have this instruction ?

subi ZL,-1 ; Increment Z by 1
sbci ZH,-1

***********************************************************
trigger a oscilloscope on I2C start ( or buy a Tektronix :-) )
The I2C start condition is SDA low while SCL is high, so we can make a little circuit of hardware.
The only thing we need is a D-latch.

SCL ------*D Q*------ out


SDA ----o>*C
connect the trigger to out and select Rising edge on the scope !

**********************************************************

Init_Random:        ;first time
	ldi	TEMP,$AA	;Init the random number generator
	mov	RAND1,TEMP	;since a 00,00,00 state will not
	mov	RAND2,TEMP	;progress.
	mov	RAND3,TEMP	;you can get a timer to pre load first time
	ret
**********************************************************
 simple 24bit random generator
**********************************************************
simpler:

	rol	RAND1		;Shift the bits ->Carry
	rol	RAND2		;RAND are register or Ram
	rol	RAND3
	BRCC rr2
	ldi TEMP,0x87
	eor RAND1,TEMP
rr2:
	ret
*********************************************************

100 REM *********************** DEZHEX.BAS **************
110 REM * Umwandlung von Dezimalzahlen in Hex-Zahlen *
120 REM *************************************************
130 CLS
135 A$="0123456789ABCDEF"
140 PRINT "Von Dezimal zu Binär"
150 INPUT "DEZ = ";D
155 D$=""
170 M=D:D=INT(D/16)
180 M=M-D*16+1
190 D$=MID$(A$,M,1)+D$
200 IF D > 0 THEN 170
210 IF LEN (D$) < 4 THEN D$ = "0" + D$: GOTO 210
220 PRINT "Hex = ";D$

100 REM *********************** DEZBIN.BAS *******************
110 REM * Umwandlung von Dezimalzahlen in Binärzahlen *
120 REM ******************************************************
130 CLS
140 PRINT "Von Dezimal zu Binär"
150 INPUT "DEZ = ";D:B$=""
160 D = D/2
170 IF D = INT(D) THEN B$ = "0" + B$
180 IF D <>INT(D) THEN B$ = "1" + B$
190 D = INT(D)
200 IF D > 0 THEN 160
210 IF LEN (B$) < 8 THEN B$ = "0" + B$: GOTO 210
220 PRINT "BIN = ";B$

100 REM *********************** HEXDEZ.BAS *******************
110 REM * Umwandlung von Hex-Zahlen in Dezimalzahlen *
120 REM ******************************************************
125 A$ = "0123456789abcdef"
130 CLS
140 PRINT "Hex zu Dezimal"
150 INPUT "Hex = ";H$
160 L=LEN(H$):Y =-1:D=0
170 FOR I = L TO 1 STEP -1:X=0:Y=Y+1
180 X=X+1:IF MID$(A$,X,1)<>MID$(H$,I,1) THEN 180
190 D = D +(X - 1)*16^Y:NEXT I
200 PRINT "Dez = ";D