1 / 30

Les 6 - onderwerpen

Les 6 - onderwerpen. Volgende weken Keypad, dender (bouncing) U(S)ART IR Motortjes C library Opdrachten: toetsenbord en UART (asm), LCD (C). Na vandaag. Week 22 maandag 32 mei : inhaalles voor de maandag-klas Week 24 : projectweek! maandag 14 juni : SLO / ABC

taima
Download Presentation

Les 6 - onderwerpen

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Les 6 - onderwerpen • Volgende weken • Keypad, dender (bouncing) • U(S)ART • IR • Motortjes • C library • Opdrachten: • toetsenbord en UART (asm), • LCD (C) Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  2. Na vandaag Week 22 maandag 32 mei : inhaalles voor de maandag-klas Week 24 : projectweek! maandag 14 juni : SLO / ABC docent(en) aanwezig : wo, vry: 10:00 – 14:00 Week 25 : projectweek! docent(en) aanwezig : di: 10:00 – 14:00 donderdag 24 juni : beoordeling woensdag-klas 10:00 – 15:00 vrijdag 25 juni : beoordeling maandag-klas 10:00 – 15:00 Practicum opgaven kunnen uiterlijk dinsdag 26 juni worden afgetekend. Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  3. keypad DB038 manual 2.18 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  4. Keypad lezen • Maak pin RA1 een ingang (bit 1 in TRISA) • Maak poort A een digitale poort: ANSEL = 0 • Zet een waarde 0x01, 0x02, 0x04 of 0x08 op PORTD • Zet een waarde 4 .. 7 op PORTE • Lees pin RA1 • Doe dit voor alle 16 toetsen DB038 manual 2.18 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  5. Keypad lezen - demo main_loop: BCF PORTA_SHADOW, 2 LCALL PORTA_FLUSH LCALL kbd_read XORLW 0xFF MOVWF PORTD_SHADOW LCALL PORTD_FLUSH MOVLW .4 MOVWF PORTE_SHADOW LCALL PORTE_FLUSH BSF PORTA_SHADOW, 2 LCALL PORTA_FLUSH LCALL M10WAIT LGOTO main_loop END errorlevel -307 errorlevel -302 #include <DB038-01.INC> #include <kbd.inc> Archive: kbd-asm.zip Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  6. Keypad lezen – kbd.inc kbd_read: banksel TRISA bsf TRISA, 1 banksel TRISD clrf TRISD banksel TRISE clrf TRISE banksel ANSEL clrf ANSEL banksel 0 kbd_test 1, 4, kbd_S kbd_test 1, 5, kbd_0 kbd_test 1, 6, kbd_H kbd_test 1, 7, kbd_D kbd_test 2, 4, kbd_7 kbd_test 2, 5, kbd_8 kbd_test 2, 6, kbd_9 kbd_test 2, 7, kbd_C kbd_test 4, 4, kbd_4 kbd_test 4, 5, kbd_5 kbd_test 4, 6, kbd_6 kbd_test 4, 7, kbd_B kbd_test 8, 4, kbd_1 kbd_test 8, 5, kbd_2 kbd_test 8, 6, kbd_3 kbd_test 8, 7, kbd_A retlw kbd_none kbd_inc_end: LGOTO kbd_inc_end #define kbd_0 .0 #define kbd_1 .1 #define kbd_2 .2 #define kbd_3 .3 #define kbd_4 .4 #define kbd_5 .5 #define kbd_6 .6 #define kbd_7 .7 #define kbd_8 .8 #define kbd_9 .9 #define kbd_A .10 #define kbd_B .11 #define kbd_C .12 #define kbd_D .13 #define kbd_S .14 #define kbd_H .15 #define kbd_none .16 kbd_test macro D, E, K movlw D movwf PORTD_SHADOW LCALL PORTD_FLUSH movlw E movwf PORTE_SHADOW LCALL PORTE_FLUSH BTFSC PORTA, 1 RETLW K endm Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  7. Switch bounce (denderen) Als je een drukknop indrukt maakt hij niet 1 keer contact: hij dendert een tijdje (maximaal ~ 50 ms)

  8. PIC - USART USART = 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 en Vista hebben 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 (?)) • In de image staat een icoon ?

  9. PIC - USART power van de 2e USB poort DB038 manual 2.4

  10. 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

  11. 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) 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)

  12. 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 Archive: uart.zip

  13. PIC – USART – demo code main MAIN CALL UART_INIT MOVLW 'H' CALL UART_CHAR_SEND MOVLW 'i' CALL UART_CHAR_SEND CALL UART_CLRF_SEND MAIN_LOOP CALL UART_CHAR_RECEIVE SKPC GOTO MAIN_LOOP MOVWF Char MOVLW '"' CALL UART_CHAR_SEND MOVFW Char CALL UART_CHAR_SEND MOVLW '"' CALL UART_CHAR_SEND CALL UART_CLRF_SEND GOTO MAIN_LOOP Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  14. De IR ontvanger • RA2 must be a digital input • RE0..RE2 outputs, value 0b110 DB038 manual 2.8

  15. De IR ontvanger • TFM5360 of TSOP1736 • (alleen) gevoelig voor een ~ 36 kHz signaal. • Dat signaal mag niet continu zijn (goed is bv.1 kHz: 500 us signaal, 500 us uit)

  16. De IR ontvanger (alleen) gevoelig voor een 36 kHz signaal. Bij 10% afwijking, dus 33-40 kHz, 60% vd. Afstand.

  17. De IR ontvanger Aanbevolen: puls >= 400uS, periode =< 0.4

  18. De IR ontvanger

  19. Eenvoudig IR zenden / ontvangen • 36 kHz  28 us per puls  5 * 28 instructies per fase (hoog en laag) • 400 us / 28 us  minimaal 14 pulsen, neem bv 30 pulsen • Onmiddelijk daarna de IR ingang lezen (laag == signaal gedetecteerd) • Pauze! (bv. 400 us) • herhaal

  20. DB038 - motortjes 20 Voeding, bv 12V Motor aansluitingen Driver chips Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  21. H-brug (H-bridge) 21 Motor 1 Motor 2 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  22. 22 DB038 manual 2.19 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  23. 23 Wat moet je op RC0..RC5 zetten om het onderstaande te bereiken: • Motor 1 (links) vooruit, motor 2 (rechts) vooruit • Links vooruit, rechts op de rem (bocht naar rechts) • Links achteruit, rechts vooruit (draai om de as naar links) DB038 manual 2.19 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  24. 24 PIC programmeren in C • Gewoon in MPLAB • DB038 manual hoofdstuk 5 • Gewoondubbel-klikken op de .mcp file van een bestaand C project. • Let op de omvang van de integer types • Compiler handelt pages en banks af • De 8-level stack limit bestaatnog steeds! • PORTA, ADRESL, etc zijn al gedefinieerd Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  25. 25 integers Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  26. 26 C libraries Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  27. 27 LCD library void lcd_init( unsigned char x, unsigned char y ); void lcd_char_print( char c ); // note: ’\v’ void lcd_string_print( const char *p ); Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  28. 28 Simpel C voorbeeld #include "db038-leds.h" #include "db038-adc.h" void main(void){ volatile unsigned int ad_result; for(;;){ ad_result = adc_potmeter(); display_decimal_show( ad_result, 0, 0, 10 ); } } Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  29. oefening 1 : toetsenbord, UART (asm) Schrijf – met behulp van de de programma’s - een programma dat het toetsenbord leest, en via de UART laat zien welke toets er is ingedrukt. Je programma moet ook reageren als er door de PC een character naar de PIC wordt verzonden. Bepaal zelf hoe. Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  30. oefening 2 : LCD (C) Schrijf – in C – een programma dat gebruik maakt van het LCD, en ten minste 1 andere peripheral (A/D, UART, toetsjes, IR, etc) op het bord. Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

More Related