logo

Select Sidearea

Populate the sidearea with useful widgets. Itโ€™s simple to add images, categories, latest post, social media icon links, tag clouds, and more.
[email protected]
+1234567890
 

Interfacing AVR Tiny231 with keyboard PC PS2

#include <tiny2313a.h>           // Alphanumeric LCD functions#include <alcd.h>#include <stdlib.h>#include <delay.h>           // Declare your global variables hereunsigned char clock_cache = 0,heksa_tombol = 0,val=0,nilai=0,nil1=0,nil2=0,nil3=0;char snilai[7];int niltot=0;
void button_exec(){           //lcd_clear();           val=heksa_tombol;           if(val==22){nilai=1;}           if(val==30){nilai=2;}           if(val==38){nilai=3;}           if(val==37){nilai=4;}           if(val==46){nilai=5;}           if(val==54){nilai=6;}           if(val==61){nilai=7;}           if(val==62){nilai=8;}           if(val==70){nilai=9;}           if(val==69){nilai=0;}           }
interrupt [EXT_INT0] void ext_int0_isr(void){ // Place your code here clock_cache++;
 if(clock_cache==0x0b) {           button_exec();clock_cache = 0;heksa_tombol=0; } else if(clock_cache>0x01) {  if(PIND.3==1)  {   switch(clock_cache)   {           case 0x02:           heksa_tombol++;break;           case 0x03:           heksa_tombol = heksa_tombol + 2;break;           case 0x04:           heksa_tombol = heksa_tombol + 4;break;           case 0x05:           heksa_tombol = heksa_tombol + 8;break;           case 0x06:           heksa_tombol = heksa_tombol + 16;break;           case 0x07:           heksa_tombol = heksa_tombol + 32;break;           case 0x08:           heksa_tombol = heksa_tombol + 64;break;           case 0x09:           heksa_tombol = heksa_tombol + 128;break;   }  } }
}
void main(void){           // Declare your local variables here
// Crystal Oscillator division factor: 1           #pragma optsize-           CLKPR=0x80;           CLKPR=0x00;           #ifdef _OPTIMIZE_SIZE_           #pragma optsize+           #endif
// Input/Output Ports initialization           // Port A initialization           // Func2=In Func1=In Func0=In            // State2=T State1=T State0=T            PORTA=0x00;           DDRA=0x00;
// Port B initialization           // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=In Func0=In                       // State7=T State6=T State5=T State4=T State3=0 State2=T State1=T State0=T                       PORTB=0x00;           DDRB=0x08;
// Port D initialization           // Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In            // State6=T State5=T State4=T State3=T State2=P State1=T State0=T            PORTD=0x06;           DDRD=0x01;
// Timer/Counter 0 initialization           // Clock source: System Clock           // Clock value: Timer 0 Stopped           // Mode: Normal top=0xFF           // OC0A output: Disconnected           // OC0B output: Disconnected           TCCR0A=0x00;           TCCR0B=0x00;           TCNT0=0x00;           OCR0A=0x00;           OCR0B=0x00;
// Timer/Counter 1 initialization           // Clock source: System Clock           // Clock value: 8000,000 kHz           // Mode: Fast PWM top=0x00FF           // OC1A output: Non-Inv.           // OC1B output: Discon.           // Noise Canceler: Off           // Input Capture on Falling Edge           // Timer1 Overflow Interrupt: Off           // Input Capture Interrupt: Off           // Compare A Match Interrupt: Off           // Compare B Match Interrupt: Off           TCCR1A=0x81;           TCCR1B=0x09;           TCNT1H=0x00;           TCNT1L=0x00;           ICR1H=0x00;           ICR1L=0x00;           OCR1AH=0x00;           OCR1AL=0x00;           OCR1BH=0x00;           OCR1BL=0x00;
// External Interrupt(s) initialization           // INT0: On           // INT0 Mode: Falling Edge           // INT1: Off           // Interrupt on any change on pins PCINT0-7: Off           GIMSK=0x40;           MCUCR=0x02;
           // Timer(s)/Counter(s) Interrupt(s) initialization           TIMSK=0x00;
// Universal Serial Interface initialization           // Mode: Disabled           // Clock source: Register & Counter=no clk.           // USI Counter Overflow Interrupt: Off           USICR=0x00;
// USART initialization           // USART disabled           UCSRB=0x00;
// Analog Comparator initialization           // Analog Comparator: Off           // Analog Comparator Input Capture by Timer/Counter 1: Off           ACSR=0x80;           DIDR=0x00;
// Alphanumeric LCD initialization           // Connections are specified in the           // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:           // RS - PORTB Bit 0           // RD - PORTB Bit 1           // EN - PORTB Bit 2           // D4 - PORTB Bit 4           // D5 - PORTB Bit 5           // D6 - PORTB Bit 6           // D7 - PORTB Bit 7           // Characters/line: 8           lcd_init(16);
// Global enable interrupts#asm("sei")while (1) {  do {     }           while (val>0&&val<=224);            itoa(nilai,snilai);lcd_gotoxy(0,0);lcd_puts(snilai);           delay_ms(25);           do {           }           while (val>0&&val<=224);            itoa(nilai,snilai);lcd_gotoxy(1,0);lcd_puts(snilai);           nil2=nilai*10;           delay_ms(25);           do {           }           while (val>0&&val<=224);            itoa(nilai,snilai);lcd_gotoxy(2,0);lcd_puts(snilai);           nil3=nilai;           delay_ms(25);           niltot=nil1+nil2+nil3;   }}