SL ("SLeep" ?) kallas även CS ("Chip Select") i databladet...

Jag såg så klart bara CS när jag kollade...
Hur som helst...
En tips bara...
Du sparar *massor* av jobb om du skaffar en processor med inbyggd USART.
Programvaru USART är lite 80-tal...
Kod: Markera allt
;**** A P P L I C A T I O N N O T E A V R 3 0 4 ************************
;*
;* Title: Half Duplex Interrupt Driven Software UART
;* Version: 1.0
;* Last updated: 97.07.18
;* Target: AT90Sxxxx (All AVR Devices)
;*
;* Support E-mail: avr@atmel.com
;*
;* Code Size :72 words
;* Low Register Usage :2
;* High Register Usage :5
;* Interrupt Usage :External Interrupt,
;* Timer/Counter0 overflow interrupt
;*
;* DESCRIPTION
;*
;* This application note describes how to make a half duplex software UART
;* on any AVR device with the 8-bit Timer/Counter0 and External Interrupt.
;* As a lot of control applications communicate in one direction at a time
;* only, a half duplex UART will limit the usage of MCU resources.
;*
;* The constants N and R determine the data rate. R selects clock frequency
;* as described in the T/C Prescaler in the AVR databook. If the T/C pre-
;* scaling factor is denoted C, the following expression yields the data rate:
;*
;* XTAL
;* BAUD = ------ min. N*C = 17
;* N*C max. N = 170
;*
;* Absolute minimum value for N*C is 17 (which causes the interrupt flag to be
;* set again before the interrupt is finished). Absolute maximum is 170.
;* (Caused by the 1.5bit-lenght that is necessary to receive bits correctly.)
;*
;* The UART uses PD2 as receive pin because it utilizes the external interrupt.
;* The transmit-pin is PD4 in this example, but it can be any other pins.
;*
;* Since the UART is half duplex, it can either send or recieve data. It can't
;* do both simoutaneausly. When idle it will automatically recieve incoming
;* data, but if it is transmitting data while incoming data arrives, it will
;* ignore it. Also, if u_transmit is called without waiting for the 'READY' bit
;* in the 'u_status' register to become cleared, it will abort any pending
;* reception or transmittal.
Kod: Markera allt
.INCLUDE "TN13DEF.INC"
.DEF A = R16
.ORG 0000
RJMP ON_RESET
.ORG 0003
RJMP TIM0_OVF
ON_RESET:
SBI DDRB,0 ;SET PORTB0 FOR OUTPUT
SBI DDRB,2
CBI DDRB,1
LDI A,0b0000_0001 ;no prescaling
OUT TCCR0B,A ;TIMER/COUNTER CONTROL REGISTER "B"
LDI A,0b0000_0010 ;ENABLE TIMER-OVERFLOW INTERUPT
OUT TIMSK0,A
LDI A,3 ;PRELOAD THE TIMER
OUT TCNT0,A
SEI ;ENABLE INTERUPTS GLOBALLY
MAIN_LOOP:
SBIS PINB,1
SBI PORTB,2 ;turn of led
SBIC PINB,1
CBI PORTB,2 ;turn on led
RJMP MAIN_LOOP
TIM0_OVF:
SBI PINB,0 ;FLIP THE 0 BIT
RETI
Well, jag har inte ställt in någonting...Det beror ju på hur du har ställt in den (processorn).
Som jag sa, jag hittar inte riktigt vad den inre frekvensen är. Det står på sida 25 att den är 9,6 eller 4,8MHz. Jag förstår inte vad som avgör skillnaden. Jag har dock provat med att skala frekvensen till ir-dioden från bägge dessa frekvenser, men det fungerade inte med 4,8 heller.Vad är det som du nte hittar?