Sei sulla pagina 1di 5

http://www.mikroe.

com/eng/chapters/view/82/capitulo-4-ejemplos/#c4v13 unsigned short kp,cnt; char txt[5]; void main() { cnt=0; keypad_Init(&PORTD); Lcd8_Init(&PORTC,&PORTB,0,2,1,7,6,5,4,3,2,1,0); Lcd8_Cmd(LCD_CLEAR); Lcd8_Cmd(LCD_CURSOR_OFF); Lcd8_Out(1,1,"Key:"); Lcd8_Out(2,1,"Times:"); do{ kp=0; pressed do kp=Keypad_Read(); while(!kp); switch(kp) { case 10: kp=42; break; case 11: kp=48; break; case 12: kp=35; break; default: kp+=48; } cnt++; Lcd9_Chr(1,10,kp); if(cnt==255){cnt=0;Lcd8_Out(2,10,"");} WordToStr(cnt,txt); Lcd8_Out(2,10,txt); }while(1); }

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++ void Tone1() { Sound_Play(659, 250); // Frecuencia = 659Hz, duracin = 250ms } void Tone2() { Sound_Play(698, 250); // Frecuencia = 698Hz, duracin = 250ms } void Tone3() { Sound_Play(784, 250); // Frecuencia = 784Hz, duracin = 250ms } void Melody1() { // Tone1(); Tone2(); Tone1(); Tone2(); Tone1(); Tone2(); Tone1(); Tone2(); Tone1(); Tone2(); Componer Tone3(); Tone3(); Tone3(); Tone3(); Tone3(); una meloda divertida 1 Tone3(); Tone3(); Tone3();

Tone3(); Tone3(); Tone2(); Tone2(); Tone1(); } void ToneA() { // Tono A Sound_Play( 880, 50); } void ToneC() { // Tono C Sound_Play(1046, 50); } void ToneE() { // Tono E Sound_Play(1318, 50); } void Melody2() { // Componer una meloda divertida 2 unsigned short i; for (i = 9; i > 0; i--) { ToneA(); ToneC(); ToneE(); } } void main() { ANSEL = 0; ANSELH = 0; TRISB = 0xF0; // Todos los pines de E/S son digitales // Pines RB7-RB4 se configuran como entradas

// RB3 se configura como salida Sound_Init(&PORTB, 3); Sound_Play(1000, 500); while (1) { if (Button(&PORTB,7,1,1)) Tone1(); while (PORTB & 0x80) ; if (Button(&PORTB,6,1,1)) Tone2(); while (PORTB & 0x40) ; if (Button(&PORTB,5,1,1)) Melody2(); while (PORTB & 0x20) ; if (Button(&PORTB,4,1,1)) Melody1(); while (PORTB & 0x10) ; } } +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // LCD module connections sbit sbit sbit sbit sbit sbit LCD_RS LCD_EN LCD_D4 LCD_D5 LCD_D6 LCD_D7 at at at at at at RB4_bit; RB5_bit; RB0_bit; RB1_bit; RB2_bit; RB3_bit; // RB7 genera Tono1 // Esperar que se suelte el botn // RB6 genera Tono2 // Esperar que se suelte el botn // RB5 genera meloda 2 // Esperar que se suelte el botn // RB4 genera meloda 1 // Esperar que se suelte el botn

sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections char char char char txt1[] txt2[] txt3[] txt4[] = = = = "LuisP"; "ErwinC"; "com2 y sist dina"; "Final Final"; // Loop variable // Function used for text moving // You can change the moving speed here

char i; void Move_Delay() { Delay_ms(500); } void main(){ Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Out(1,2,txt3); Lcd_Out(2,3,txt4); Delay_ms(2000); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,6,txt1); Lcd_Out(2,6,txt2); Delay_ms(900); // Moving text for(i=0; i<4; i++) { Lcd_Cmd(_LCD_SHIFT_RIGHT); Move_Delay(); } while(1) { for(i=0; i<8; i++) { Lcd_Cmd(_LCD_SHIFT_LEFT); Move_Delay(); } for(i=0; i<8; i++) { Lcd_Cmd(_LCD_SHIFT_RIGHT); Move_Delay(); } } }

// Initialize LCD // Clear display // Cursor off // Write text in first row // Write text in second row // Clear display // Write text in first row // Write text in second row

// Move text to the right 4 times

// Endless loop // Move text to the left 7 times

// Move text to the right 7 times

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//Luces secuenciales auto radiocontrol void main() { trisa=0; while(1) { porta=0b00000001; delay_ms(5000); porta=0b00000010; delay_ms(5000); porta=0b00000100; delay_ms(5000); porta=0b00001000; delay_ms(5000); } } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //teclado y lcd unsigned short kp, cnt, oldstate = 0; char txt[6]; // Keypad module connections char keypadPort at PORTD; // End Keypad module connections // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections void main() { cnt = 0; Keypad_Init(); Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Out(1, 1, "1"); Lcd_Out(1, 1, "Key :"); Lcd_Out(2, 1, "Times:"); do { kp = 0; // Reset counter // Initialize Keypad // Initialize LCD // Clear display // Cursor off // Write message text on LCD

// Reset key code variable

// Wait for key to be pressed and released

do // kp = Keypad_Key_Press(); kp = Keypad_Key_Click(); while (!kp); // Prepare value for output, transform switch (kp) { //case 10: kp = 42; break; // '*' //case 11: kp = 48; break; // '0' //case 12: kp = 35; break; // '#' //default: kp += 48; case case case case case case case case case case case case case case case case } if (kp != oldstate) { cnt = 1; oldstate = kp; } else { cnt++; } Lcd_Chr(1, 10, kp); if (cnt == 255) { cnt = 0; Lcd_Out(2, 10, " } WordToStr(cnt, txt); Lcd_Out(2, 10, txt); } while (1); } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Pressed key differs from previous 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: kp kp kp kp kp kp kp kp kp kp kp kp kp kp kp kp = = = = = = = = = = = = = = = = 49; 50; 51; 65; 52; 53; 54; 66; 55; 56; 57; 67; 42; 48; 35; 68; break; break; break; break; break; break; break; break; break; break; break; break; break; break; break; break; // // // // // // // // // // // // // // // // 1 2 3 A 4 5 6 B 7 8 9 C * 0 # D // Store key code in kp variable // Store key code in kp variable key to it's ASCII value // Uncomment this block for keypad4x3

// Uncomment this block for keypad4x4

// Pressed key is same as previous

// Print key ASCII value on LCD // If counter varialble overflow "); // Transform counter value to string // Display counter value on LCD

Potrebbero piacerti anche