Пн окт 02, 2017 15:11:28
#include "main.h"
#include "kb.h"
unsigned char readbuff[64] absolute 0x500;
unsigned char writebuff[64] absolute 0x540;
unsigned char modifier=0b00000000;
unsigned char reserved=0;
unsigned char keycode[6];
unsigned char progPass[17] = {0};
void interrupt(){
USB_Interrupt_Proc(); // USB servicing is done inside the interrupt
PS2_interrupt(); //Ïðåðûâàíèå ïî INT0 ïðè ïîñòóïëåíèè äàííûõ ñ PS2
}
void interrupt_low(){
PS2_Timeout_Interrupt(); //Ïðåðûâàíèå ïî timer0 ÷åðåç 1ìñ â ñëó÷àå îøèáî÷íûõ äàííûõ ïî PS2
}
void Led_Indicate(unsigned char blink){
unsigned char i;
for(i=0; i<=blink; i++){
LED_PIN = ~LED_PIN;
delay_ms(100);
}
LED_PIN = 0;
}
unsigned char ArrCmp(unsigned char * arr1, unsigned char * arr2, unsigned char pos, unsigned char ln){
unsigned char i;
for (i=0; i<ln; i++){
if(arr1[i+pos] != arr2[i]) return 0;
}
return 1;
}
void main(){
unsigned char i;
INTCON = 0;
//Initialize ports
ADCON1 = 0x0F; // Configure all PORT pins as digital
//----------
TRISA= 0b00010000;
TRISB= 0b00000011;
TRISC= 0b10111000;
//Initialize periferal
init_kb();
HID_Enable(readbuff,writebuff);
UART1_Init(9600); // Initialize hardware UART1 and establish communication at 9600 bps
delay_ms(100);
INTCON2.RBPU = 0; //Âêëó÷èòü ïîäòÿæêó
//OK indicator
Led_Indicate(2);
PWR12 = 1;
INTCON |= (1<<GIE)|(1<<PEIE);
//Main cycle
while(1) {
if(button(&PORTC, RC7, 200, 0)){
LED_PIN = 1;
PWR5 = 1;
VIDEO_PIN = 1;
delay_ms(300);
LED_PIN = 0;
}
if(keycode[0] == 0x45){
uart_write(30);
}
if(ArrCmp(&progPass, &progStr, 0, 16)){
switch(progPass[16]){
case 0x1E: UART1_Write(201); break;
case 0x1F: UART1_Write(202); break;
case 0x20: UART1_Write(203); break;
case 0x21: UART1_Write(204); break;
default: break;
}
progPass[0] = 0;
}else if(ArrCmp(&progPass, &delStr, 8, 8)){
switch(progPass[16]){
case 0x1E: UART1_Write(205); break;
case 0x1F: UART1_Write(206); break;
case 0x20: UART1_Write(207); break;
case 0x21: UART1_Write(208); break;
case 0x22: UART1_Write(209); break;
default: break;
}
progPass[8] = 0;
}
//////////////////////////////////////////////////////////////
//----------
//USB
writebuff[0]=modifier;
writebuff[1]=reserved;
writebuff[2]=keycode[0];
writebuff[3]=keycode[1];
writebuff[4]=keycode[2];
writebuff[5]=keycode[3];
writebuff[6]=keycode[4];
writebuff[7]=keycode[5];
while(!HID_Write(writebuff,8));
delay_ms(30);
}
HID_Disable();
}
Ср окт 04, 2017 16:25:14
Чт окт 05, 2017 09:46:14
MPLab не подойдет?
Чт окт 05, 2017 10:23:37
while(!HID_Write(writebuff,8));
Чт окт 05, 2017 21:08:12
Ср окт 11, 2017 17:09:00
Ср окт 11, 2017 20:29:35
Чт окт 12, 2017 12:09:45
Чт окт 12, 2017 15:15:53