Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int hex2int(char *a, unsigned int len)
- {
- int i;
- int val = 0;
- for(i=0;i<len;i++)
- if(a[i] <= 57)
- val += (a[i]-48)*(1<<(4*(len-1-i)));
- else
- val += (a[i]-55)*(1<<(4*(len-1-i)));
- return val;
- }
- 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;
- unsigned char readbuff[64] absolute 0x500;
- unsigned char writebuff[64] absolute 0x540;
- void main()
- {
- int ulaz_status;
- char hex_cifra[3];
- int tmp_broj;
- int i;
- int broj_konverzija = 0;
- ADCON1 |= 0x0F; // Configure all ports with analog function as digital
- CMCON |= 7; // Disable comparators
- Lcd_Init(); // Initialize Lcd
- HID_Enable(&readbuff,&writebuff); // Enable HID communication
- Lcd_Cmd(_LCD_CLEAR);
- Lcd_Out(1,1,"Broj karaktera:");
- while(1)
- {
- USB_Polling_Proc();
- Lcd_Out(2,1, broj_konverzija);
- ulaz_status = HID_Read();
- if(ulaz_status != 0)
- {
- for(i=0; i<64; i=i+1)
- {
- ByteToHex(readbuff[i], hex_cifra);
- tmp_broj = hex2int(hex_cifra, 2);
- if(tmp_broj == 0)
- {
- tmp_broj = 45;
- }
- else
- {
- if(tmp_broj >= 32 && tmp_broj <=126)
- {
- if(tmp_broj >= 97 && tmp_broj <=122)
- {
- tmp_broj -= 32;
- broj_konverzija++;
- }
- }
- else
- {
- tmp_broj = 45;
- }
- }
- //prevesti tmp_broj u Hex broj
- //Dobijeni Hex broj smestiti u lokaciju i
- writebuff[i]=readbuff[i];
- }
- Lcd_Out(//promenjiva za postavljanje kursora na pocetak drugog reda);
- HID_Write(&writebuff,64);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement