Christmas Lights Re: TI-H: drugs..


[Prev][Next][Index][Thread]

Christmas Lights Re: TI-H: drugs..




>//Olle
>(Maybe we should get back on topic now ;)

My brother's name is Ole.  Its a name that orrigionated in norway I think...

;***************************************************************************
;*     C O D E  F O R  T H E  I 2 C  R O U T I N E  C O L L E C T I O N
;*
;* Number               :ACXMAS002
;* File Name            :ACXMAS002.asm
;* Title                :LCDLite Display Controller
;* Date:		Version: 				Status:
;* 10.30.98		1a		Grant Stockly	Started project for
no reason except
;*
	that I was bored.
;* 10.30.98		1bR1	Grant Stockly	Finished...  Better version
later.
;*
;* Support telephone    :1-907-345-1529
;* Support email        :gussie@alaska.net
;* Target               :AT90Sxxxx (any AVR device)
;*
;* DESCRIPTION
;* This code is a christmas light controller for any I2C bus.  It was meant
;* for TI-Calculators...
;*
;* Sending a data byte to the correct address will apply that data byte to
;* the lights.
;*
;* Data Byte:
;* Bit:		0	1	2	3	4	5	6	7
;* Light:	1	2	3	4	x	x	x	x
;*
;* As you can see, only the first 4 bits do anything to the lights.
;*
;* A better version will include the ability to select custom addresses, and
;* the ability to program a set pattern into memory.
;*
;***************************************************************************

.include "1200def.inc"	;Include files for the AT90S1200
.device AT90S1200		;Tells the assembler what part we are using

;*****Global Registers
.def	temp	= 16		;Temporary variable
.def	etemp	=r17		;Extra temporary variable
.def	i2cdata	=r18		;I2C data register
.def	i2cadr	=r19		;I2C address and direction register
.def	i2cstat	=r20		;I2C temporary SREG storage
.def	xmasled	=r21		;Christmas Light Register

;**** Global I2C Constants ****
.equ	devadr	=0x50		;Slave device address
.equ	devadrm	=0x7F		;Slave multi address mask
.equ	pinmask =0x14		;<=> (1<<PD4)+(1<<PD2)
.equ	light1	=0			;Light #1 is PB0
.equ	light2	=1			;Light #2 is PB1
.equ	light3	=2			;Light #3 is PB2
.equ	light4	=3			;Light #4 is PB3

;**** Interrupt Vectors ****
	rjmp	RESET		;Reset handle
	rjmp	EXT_INT0	;INT0 handle
	rjmp	TIM0_OVF	;Timer 0 overflow handle


RESET:
	ldi		temp, (0<<DDD4)+(0<<DDD2)
	out		DDRD, temp
	ldi		temp, (0<<PD4)+(0<<PD2)
	out		PORTD, temp
	ldi		temp, (1<<ISC01)+(0<<ISC00)
	out		MCUCR, temp
	ldi		temp, (1<<INT0)
	out		GIMSK, temp
	ldi		temp, (1<<CS02)+(1<<CS01)+(0<<CS00)
	out		TCCR0, temp
Main:
	rjmp	do_start_w
	rjmp	Main
do_start_w:
	in		temp, PIND
	com		temp
	andi	temp, pinmask
	brne	do_start_w
	in		temp, PIND
	andi	temp, pinmask
do_start_w2:
	in		etemp, PIND
	andi	etemp, pinmask
	cp		etemp, temp
	breq	do_start_w2
	sbrc	etemp, PIND2
	rjmp	do_start_w
	rcall	i2c_get_adr
EXT_INT0:
	in	i2cstat,SREG
i2c_get_adr:
	ldi		i2cadr, 1
wlo_ga0:
	sbic	PIND, PIND4
	rjmp	wlo_ga0
	rjmp	first_ga
do_ga:
wlo_ga:
	sbic	PIND, PIND4
	rjmp	wlo_ga
	mov		temp, i2cadr
	andi	temp, devadrm
	cpi		temp, devadr
	in		temp, SREG
	bst		temp, 1
first_ga:
	sec
whi_ga:
	sbis	PIND, PIND4
	rjmp	whi_ga
	sbis	PIND, PIND2
	clc
	rol		i2cadr
	brcc	do_ga
wlo_ca:
	sbic	PIND, PIND4
	rjmp	wlo_ca
	brts	i2c_adr_ack
	rjmp	i2c_adr_miss
i2c_adr_ack:
	sbi		DDRD, DDD2
whi_aa:
	sbis	PIND,PIND4
	rjmp	whi_aa
	lsr		i2cadr
	brcc	i2c_master_write
i2c_master_write:
wlo_mw0:
	sbic	PIND, PIND4
	rjmp	wlo_mw0
	cbi		DDRD, DDD2
whi_mw:
	sbis	PIND, PIND4
	rjmp	whi_mw
	in		temp, PIND
	andi	temp, pinmask
do_mw:
	in		etemp, PIND
	andi	etemp, pinmask
	cp		etemp, temp
	breq	do_mw
	sbrs	etemp, PIND4
	rjmp	receive_data
	sbrs	etemp, PIND2
	rjmp	i2c_stop
receive_data:
	ldi		i2cdata, 2
	sbrc	temp, PIND2
	ldi		i2cdata, 3
do_rd:
wlo_rd:
	sbic	PIND, PIND4
	rjmp	wlo_rd
	sec
whi_rd:
	sbis	PIND, PIND4
	rjmp	whi_rd
	sbis	PIND, PIND2
	clc
	rol		i2cdata
	brcc	do_rd
i2c_dat_ack:
wlo_da:
	sbic	PIND, PIND4
	rjmp	wlo_da
	sbi		DDRD, DDD2
whi_da:
	sbis	PIND, PIND4
	rjmp	whi_da
	sbi	DDRD,DDD4			;Start Wait state
	sbrs	i2cdata, 0		;Skip if bit 0 is set
	cbi		PORTB, light1	;Clear Christmas light #1
	sbrc	i2cdata, 0		;Skip if bit o is clear
	sbi		PORTB, light1	;Set Christmas light #1
	sbrs	i2cdata, 1		;Skip if bit 1 is set
	cbi		PORTB, light2	;Clear Christmas light #2
	sbrc	i2cdata, 1		;Skip if bit 1 is clear
	sbi		PORTB, light2	;Set Christmas light #2
	sbrs	i2cdata, 2		;Skip if bit 2 is set
	cbi		PORTB, light3	;Clear Christmas light #3
	sbrc	i2cdata, 2		;Skip if bit 2 is clear
	sbi		PORTB, light3	;Set Christmas light #3
	sbrs	i2cdata, 3		;Skip if bit 3 is set
	cbi		PORTB, light4	;Clear Christmas light #4
	sbrc	i2cdata, 3		;Skip if bit 3 is clear
	sbi		PORTB, light4	;Set Christmas light #4
	cbi	DDRD,DDD4			;End Wait state
	rjmp	i2c_master_write
TIM0_OVF:
	in	i2cstat,SREG
i2c_adr_miss:
whi_dac:
	sbis	PIND, PIND4
	rjmp	whi_dac
wlo_dac:
	sbic	PIND, PIND4
	rjmp	wlo_dac
	ldi		temp, (0<<TOIE0)
	out		TIMSK, temp
	ldi		temp, (1<<INT0)
	out		GIMSK, temp
i2c_wait_cond:
whi_wc:
	sbis	PIND, PIND4
	rjmp	whi_wc
	in		temp, PIND
	andi	temp, pinmask
do_wc:
	in		etemp, PIND
	andi	etemp, pinmask
	cp		etemp, temp
	breq	do_wc
	sbrs	etemp,PIND4
	rjmp	i2c_skip_byte
	sbrs	etemp,PIND2
	rjmp	i2c_get_adr
i2c_stop:
	ldi		temp, (0<<ISC01)+(0<<ISC00)
	out		MCUCR, temp
	ldi		temp, (1<<ISC01)+(0<<ISC00)
	out		MCUCR, temp
	out		SREG, i2cstat
	reti
i2c_skip_byte:
	ldi		temp, -7
	out		TCNT0, temp
	ldi		temp, (1<<TOIE0)
	out		TIMSK, temp
	ldi		temp, (0<<INT0)
	out		GIMSK, temp
	out		SREG, i2cstat
	reti


Follow-Ups: References: