Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
12PROJ5 – PIC assembler
Les 6 - onderwerpen
• seriele interface (UART - USB - VCP)• IR
De datum om je eindopdracht te laten zien is woensdag 8 november, 14:50 .. 17:50.
(evt vanaf 13:10) (volgende week mag ook...)
Inschrijven in Osiris is verplicht
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
22PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
32PROJ5 – PIC assembler
PIC - USARTUSART = Universal Synchronous / Asynchronous Receiver
+ Transmitter
• wij gebruiken asynchroon• PIC UART pins zijn verbonden met een FT232R USB-to-
asynchronous converter• Op de PC wordt een (virtuele) seriele poort aangemaakt
(XP heeft al een driver)control panel system hardware device manager ports
• evt driver van www.ftdichip.com gebruiken• op de PC gebruik je een terminal, bv HyperTerminal
(hypertrm, 19k2, no parity, no flow control, hu: com3)
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
42PROJ5 – PIC assembler
PIC - USART
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
52PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
62PROJ5 – PIC assembler
BRGH = 0 BRGH = 1
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
72PROJ5 – PIC assembler
100- 1 - -R
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
82PROJ5 – PIC assembler
RR -0101 -
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
92PROJ5 – PIC assembler
PIC – USART - init
make TxD (RC6) output, RxD (RC7) input
SPBRG: 19k2 value for high speed
TXSTA: 8 bit, enable, asynch, high speed
RCSTA: enable, 8 bit, continuous, no ADDEN
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
102PROJ5 – PIC assembler
PIC – USART - send
• wacht tot TSR bit aangeeft dat TSR empty is• copy het te verzenden byte naar TXREG• (wacht tot TSR bit aangeeft dat TSR empty is)
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
112PROJ5 – PIC assembler
PIC – USART - receive
• als OERR bit gezet is:– clear CREN– wacht een paar instructies– set CREN
• als PIR1 : TXIF op 0 gezet is:– lees RCREG, dit is het ontvangen byte
(anders is er nog niets ontvangen)
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
122PROJ5 – PIC assembler
power van de 2e USB poort
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
132PROJ5 – PIC assembler
PIC – USART – demo code subroutines
UART_INIT : call to inistialise the UART for 19k2
UART_CHAR_SEND : sends the char in W
UART_CHAR_RECEIVE : checks the UART for a received char, C flag set when a char is received (char in W), C flag is cleared when no char is received
UART_CLRF_SEND : sends the CR LF sequence
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
142PROJ5 – PIC assembler
PIC – USART – demo code mainMAIN
CALL UART_INIT
MOVLW 'H'CALL UART_CHAR_SENDMOVLW 'i'CALL UART_CHAR_SENDCALL UART_CLRF_SEND
MAIN_LOOPCALL UART_CHAR_RECEIVESKPC
GOTO MAIN_LOOPMOVWF CharMOVLW '"'CALL UART_CHAR_SENDMOVFW CharCALL UART_CHAR_SENDMOVLW '"'CALL UART_CHAR_SENDCALL UART_CLRF_SENDGOTO MAIN_LOOP
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
152PROJ5 – PIC assembler
De IR ontvanger (1)
• (alleen) gevoelig voor een ~ 36 kHz signaal.
• Dat signaal mag niet continu zijn
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
162PROJ5 – PIC assembler
De IR ontvanger (2)
(alleen) gevoelig voor een 36 kHz signaal.
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
172PROJ5 – PIC assembler
De IR ontvanger (3)
Aanbevolen: puls >= 400uS, periode =< 0.4
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
182PROJ5 – PIC assembler
De IR ontvanger (4)
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
192PROJ5 – PIC assembler
Eenvoudig IR zenden / ontvangen
• 36 kHz 28 us per puls 5 * 28 instructies per fase (hoog of laag)
• 400 us / 28 us minimaal 14 pulsen, neem bv 30 pulsen
• Onmiddelijk daarna de IR ingang lezen (laag == signaal gedetecteerd)
• Pauze!• herhaal
Top Related