Refer to HERE
Hi everyone,
I am trying to make an interface between an android phone and microcontroller using the HC-06 Bluetooth module.
인터페이스를 만들려한다. between 안드로이드 폰 & 마이크로컨트롤러사이에 using the HC-06을 써서.
I started this morning by trying it out on Arduino UNO
and as there are many tutorials on the internet about the same,
I managed in perhaps the first hour to send characters from my phone.
But am a fan of PIC microcontrollers and so I decided to go for the major adventure of the day.
As it however turns out about 12 hours later, its turning into a nightmare.
I can pair with my phone and initialize the UART communication without problems.
난 페어할수있었다. with 내폰과 and 초기화할수있었다. the UART 통신을 without 문제없이.
When I start typing, I can also tell that there is signal being detected by my PIC.
when 내가 start 타이핑하기시작했을때 난 can also 말할수있었다. there is 시그널이있다고. being 감지되는 by 내 PIC에 의해.
But there seems to be no data transfer except for an error.
But 없어보인다. 데이터 송신자가 except for an 에러빼고.
What could be wrong with my code.
I'm using MikroC and MPLab with PICKIT3 and Blueterm2 in Android phone.
▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
unsigned short counter=0; void interrupt() { if (INTCON.TMR0IF) { if (counter >= 20) { Soft_UART_Break(); counter = 0; // reset counter } else counter++; // increment counter INTCON.TMR0IF = 0; // Clear Timer0 overflow interrupt flag } } void main(){ unsigned char error, datain, byte_read=0, i, k=100, j=9, l=200; TRISB.F3=0; TRISA=0; PORTB=0; PORTA=0; ANSEL=0; CMCON=7; OSCCON=0B01001100; OPTION_REG = 0x04; // TMR0 prescaler set to 1:32 TMR0=0; INTCON.TMR0IE = 0; // Enable Timer0 overflow interrupt for(i=0; i<3; i++){ PORTA=255; Delay_ms(100); PORTA=0; Delay_ms(100); } error = Soft_UART_Init(&PORTB, 4, 5, 9600, 0); Eeprom_Write(0x00, error); if (error > 0) { Eeprom_Write(0x01, error); delay_ms(10); /*PORTA=error; Delay_ms(30); PORTA=0; Delay_ms(30);*/ while(1); // Stop program } Delay_ms(100); while(1) { // Endless loop INTCON.GIE = 1; // Global interrupt enable INTCON.TMR0IE = 1; // Enable Timer0 overflow interrupt byte_read = Soft_UART_Read(&error); // Read byte, then test error flag INTCON.GIE = 0; // Global interrupt disable INTCON.TMR0IE = 0; // Disable Timer0 overflow interrupt if(error==0){ Eeprom_Write(j, byte_read); //save data in Eeprom j+=1; if(j>200) j=9; PORTA=3; Delay_ms(30); Eeprom_Write(0x04, j); ////save number of characters in Eeprom PORTA=0; Delay_ms(30); PORTA = byte_read; //Eeprom_Write(j, byte_read); } else Eeprom_Write(0x05, error); //save error message in Eeprom } }
▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
---------------------------------------------------------------------------
Refer to Here.
Code C - [expand] | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | // LCD module connections sbit LCD_RS at PORTB2_bit; sbit LCD_EN at PORTB3_bit; sbit LCD_D4 at PORTB4_bit; sbit LCD_D5 at PORTB5_bit; sbit LCD_D6 at PORTB6_bit; sbit LCD_D7 at PORTB7_bit; sbit LCD_RS_Direction at DDB2_bit; sbit LCD_EN_Direction at DDB3_bit; sbit LCD_D4_Direction at DDB4_bit; sbit LCD_D5_Direction at DDB5_bit; sbit LCD_D6_Direction at DDB6_bit; sbit LCD_D7_Direction at DDB7_bit; // End LCD module connections unsigned char ackPacket[64] = ""; unsigned int i = 0; unsigned char processAck = 0, cmd = 0; #define Lo(param) ((char *)¶m)[0] #define Hi(param) ((char *)¶m)[1] #define Higher(param) ((char *)¶m)[2] #define Highest(param) ((char *)¶m)[3] const unsigned int gheader = 0xEF01; unsigned long goriginalModuleAddress = 0xFFFFFFFF; unsigned long gnewModuleAddress = 0xAABBCCDD; unsigned long gmoduleAddress = 0xFFFFFFFF; unsigned long gchipAddress = 0xFFFFFFFF; unsigned long int gpassword = 0xABCDEF01; unsigned short gturnOnPort = 1, gturnOffPort = 0; unsigned short gbufferID = 0, gpageNum2 = 0; unsigned int gpageID = 0, gnoOfTemplates = 0, gstartPage = 0, gpageNum = 0; unsigned char gdataContent[32] = ""; void UART1_Write_Byte(unsigned char byte){ UART1_Write(byte); } unsigned int findChecksum(unsigned char PID, unsigned int pLen, unsigned char instructionCode){ return (PID + pLen + instructionCode); } void cmd_GenerateImage(const unsigned int header, unsigned long int moduleAddress, unsigned char PID, unsigned int pLen, unsigned char instructionCode); //Finger Print Processing Functions //Generate Image void cmd_GenerateImage(const unsigned int header, unsigned long int moduleAddress, unsigned char PID, unsigned int pLen, unsigned char instructionCode){ UART1_Write_Byte(Hi(header)); UART1_Write_Byte(Lo(header)); UART1_Write_Byte(Highest(moduleAddress)); UART1_Write_Byte(Higher(moduleAddress)); UART1_Write_Byte(Hi(moduleAddress)); UART1_Write_Byte(Lo(moduleAddress)); UART1_Write_Byte(PID); UART1_Write_Byte(Hi(pLen)); UART1_Write_Byte(Lo(pLen)); UART1_Write_Byte(instructionCode); UART1_Write_Byte((findChecksum(PID, pLen, instructionCode) >> 8)); UART1_Write_Byte((findChecksum(PID, pLen, instructionCode) & 0xFF)); } void UART1_Interrupt() iv IVT_ADDR_USART_RXC ics ICS_AUTO { if(cmd == 7){ ackPacket[i] = UDR; i++; } if(i == 10)processAck = 1; RXC_bit = 0; } void main() { DDRB = 0xFF; PORTB = 0x00; DDRD = 0xFE; PORTD = 0x00; UART1_Init(57600); Delay_ms(2000); RXCIE_bit = 1; asm{ sei } Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,"FP Scanner"); // Write text in first row while(1){ //Send some command to FP Scanner if(!processAck){ cmd = 7; cmd_GenerateImage(gheader, gmoduleAddress, 0x01, 0x03, 0x01); } else if(processAck){ if(ackPacket[9] == 0x00){ Lcd_Out(2,1,"Finger collection "); Lcd_Out(3,1,"success "); } else if(ackPacket[9] == 0x01){ Lcd_Out(2,1,"Error when receiving"); Lcd_Out(3,1,"Package "); } else if(ackPacket[9] == 0x02){ Lcd_Out(2,1,"Can't detect finger "); } else if(ackPacket[9] == 0x03){ Lcd_Out(2,1,"Fail to collect "); Lcd_Out(3,1,"finger "); } processAck = 0; i = 0; cmd = 0; } Delay_ms(5000); } } |
'Mikro C Pro' 카테고리의 다른 글
MikroBootloader (0) | 2015.06.19 |
---|---|
MikroC pro for AVR 설치법 (0) | 2015.06.15 |
CCS 와 MikroC 의 비교 (0) | 2013.01.23 |
Making Hex (0) | 2013.01.19 |