2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

avrでシリアル

Last updated at Posted at 2018-02-27

#概要
avrでシリアルやってみた。
attiny85でアセンブラで書いた。

#環境
avr studio 4
attiny85 1mhz
tera term
usb-serial

#回路図
image

#サンプルコード
9600ボーで「U」を送る。

;software 232c send
.include "tn85def.inc"
.cseg
.org 	0

reset:
	rjmp	setup
	reti
	reti
	reti
	reti
	reti
	reti
	reti
	reti
	reti
	reti
	reti
	reti
	reti
	reti

wait:
	clr 	r0
	ldi 	r17, 4
wait1:
	dec 	r0
	brne	wait1
	dec 	r17
	brne	wait1
	ret

wait100:
	ldi 	r17, 28
	subi	r17, 1
	brcc	PC - 1
	dec 	r18
	ret

setup:
	ldi 	r16, high(RAMEND)
	out 	SPH, r16
	ldi 	r16, low(RAMEND)
	out 	SPL, r16
	sbi 	DDRB, PB1
	sbi 	PORTB, PB1
send_loop:
	cbi		PORTB, PB1 	;start
	rcall   wait100
	sbi		PORTB, PB1	;bit0
	rcall   wait100
	cbi		PORTB, PB1	;bit1
	rcall   wait100
	sbi		PORTB, PB1	;bit2
	rcall   wait100
	cbi		PORTB, PB1	;bit3
	rcall   wait100
	sbi		PORTB, PB1	;bit4
	rcall   wait100
	cbi		PORTB, PB1	;bit5
	rcall   wait100
	sbi		PORTB, PB1	;bit6
	rcall   wait100
	cbi		PORTB, PB1	;bit7
	rcall   wait100
	cbi		PORTB, PB1	;stop
	rcall   wait100
	sbi		PORTB, PB1
	rcall   wait
	rjmp	send_loop

#結果
image

以上。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?