完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我用Quicy Microchip开发板用PIC16F18326单片机,我有两个微芯片开发,一个是PIC16F18326单片机的好奇芯片开发板,另一个是PIC-Demo Plus与PIC16F1937单片机,我想存档,我需要通过GPIOPin,PAN16OP发送一个PIC16F1937的数据。她的siDICIC16F18326我需要通过GPIOPin接收这些数据。有可能吗?如果是,请帮助我如何做这件事?
以上来自于百度翻译 以下为原文 I am using Curiosity microchip development board with PIC16F18326 MCU, I have two microchip development one is Curiosity microchip development board with PIC16F18326 MCU and another is PIC DEMO plus with PIC16F1937 MCU, I am trying to archive I need to send a data from PIC16F1937 through gpio pin, another side PIC16F18326 I need to receive that data through the gpio pin. is it possible? if Yes please help me to how to do this? |
|
相关推荐
2个回答
|
|
来自HTTP://www. McCHIP.COM/FUMMS/M1050362.ASPX.为什么你开始了一个关于同一个问题的新话题?为什么这两个主题都在“MPLAB C30编译器”论坛中,这与你的硬件无关?
以上来自于百度翻译 以下为原文 Comes from http://www.microchip.com/forums/m1050362.aspx Why have you started a new topic about the same question? Why are both topics in the "MPLAB C30 compiler" forum, which has nothing to do with your hardware? |
|
|
|
这是一个为PIC16F67构建的完整程序,它使用PGC和PGD线作为PICTIT2 UART工具的一个有点敲击的串行接口。有可能修改这个代码只使用一个GPIO PIN。如果你能理解这个代码是如何工作的,你应该能够做出适当的改变。
以上来自于百度翻译 以下为原文 This is a complete program that builds for a PIC16F677 and uses the PGC and PGD lines as a bit-banged serial interface to the PICkit2 UART tool. list r=dec, n=0, c=132 errorlevel -302, -312 ; ; File: main.asm ; Target: PIC16F677 ; IDE: MPLABX 4.15 ; Assembler: MPASM v5.77 ; ; Additional files: ; P16F677.INC ; 16f677_g.lkr ; ; Description: ; ; Demo application to show reading the PIC16F677 ADC on ; three channels, AN2, AN10 and AN11. ; ; System clock is the Fast Internal Oscillator at 8MHz. ; ; Default baud rate is 9600. ; ; Wait for serial input on PORTA bit 1, the PGC pin. ; The default ADC report display is about once per second. ; ; When a byte is received it is checked for these characters: ; ; 'A' - Toggle the display of the ADC value ; '1' - Set ADC to channel 2 (RA2) ; '2' - Set ADC to channel 10 (RB4) ; '3' - Set ADC to channel 11 (RB5) ; ; Note: Characters are case sensitive and are UPPER CASE. ; ; Data is sent using a bit-bang UART on PORTA bit 0, PGD. ; ; PORTC bit 0 (RC0) is set high when UART is sending data. ; ; The target hardware is the original Low Pin Count Demo Board ; with a PIC16F677. Here are links to the hardware documentation: ; ; http://ww1.microchip.com/downloads/en/DeviceDoc/Low%20Pin%20Count%20User%20Guide%2051556a.pdf ; http://ww1.microchip.com/downloads/en/DeviceDoc/LPC%20Demo%20Board%20Schematic.pdf ; http://ww1.microchip.com/downloads/en/AppNotes/91097A.pdf ; ; Note: If you have a PICkit2 this code works with the UART tool. ; list p=16F677 #include "p16F677.inc" __CONFIG _FOSC_INTRCIO & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF #define FOSC (8000000) #define FCYC (FOSC/4) #define BAUD (9600) #define T0_RELOAD (256-(FCYC/BAUD)) #define ADC_DELAY_COUNT (50000) RESET_VECTOR CODE 0x000 pagesel start goto start ISR_DATA UDATA_SHR WREG_SAVE res 1 STATUS_SAVE res 1 PCLATH_SAVE res 1 ; ; Application wide status flags App_Status res 1 #define RX_DataAvailable App_Status,1 #define RX_FamingError App_Status,2 #define RX_OverrunError App_Status,3 #define ADC_Sample App_Status,4 #define ADC_Show_Sample App_Status,5 ; ; Serial data TX_Data res 1 RX_Data res 1 UART_State res 1 #define TX_START (TxStart-State_0) #define RX_START (RxStart-State_0) #define TXD_BIT PORTA,0 #define RXD_BIT PORTA,1 ; ; Interrupt vector ; ISR_VECTOR CODE 0x004 movwf WREG_SAVE movf STATUS,W clrf STATUS movwf STATUS_SAVE movf PCLATH,W movwf PCLATH_SAVE clrf PCLATH ; ; TIMER0 ISR ; This is a bit banged half duplex UART ; ; Note: ; The TIMER0 interrupt uses a PC relative ; jump table to process the transmitter state. ; This jump table must be within a 256 byte ; program memory page. ; ISR_TMR0: btfsc INTCON,T0IE btfss INTCON,T0IF goto ISR_TMR0_Exit bcf INTCON,T0IF movlw T0_RELOAD+3 addwf TMR0,F decfsz UART_State,W ; skip if transmitter is empty goto UART_DoState ; ; TX empty ; TX_State_Empty: bcf INTCON,T0IE ; Disable interrupt when TX empty ; ; Stop bit ; TX_State_Stop: bsf TXD_BIT goto ISR_Exit UART_DoState: andlw 0x0F ; This prevents a crash but does not prevent movwf UART_State ; data errors when UART_state is corrupted. addwf PCL,F State_0:goto TX_State_Empty ; TX Empty goto TX_State_Stop ; TX Stop goto TX_State_Data ; TX Data 7 goto TX_State_Data ; TX Data 6 goto TX_State_Data ; TX Data 5 goto TX_State_Data ; TX Data 4 goto TX_State_Data ; TX Data 3 goto TX_State_Data ; TX Data 2 goto TX_State_Data ; TX Data 1 goto TX_State_Data ; TX Data 0 TxStart:goto TX_State_Start ; TX Start goto TX_State_Stop ; TX Stop goto TX_State_Stop ; TX Stop goto TX_State_Stop ; TX Stop goto RX_State_Stop ; RX Stop bit RxStart:goto RX_State_Data ; RX Data bit ; ; Start bit ; TX_State_Start: bcf TXD_BIT goto ISR_Exit ; ; Data bits ; TX_State_Data: btfss TX_Data,0 bcf TXD_BIT btfsc TX_Data,0 bsf TXD_BIT rrf TX_Data,F goto ISR_Exit ; ; RX Stop bit ; RX_State_Stop: btfss RXD_BIT ; Skip if stop bit present bsf RX_FamingError btfsc RX_DataAvailable ; Skip if data buffer available bsf RX_OverrunError bsf RX_DataAvailable ; Assert new data arrived bcf INTCON,T0IE ; Disable interrupt when RX complete goto ISR_Exit ; ; RX Data bit ; RX_State_Data: btfsc RXD_BIT ; CARRY always zero when state starts setc ; Set CARRY if RX data is ZERO rrf RX_Data,F ; Shift in bit skpc ; CARRY is set when all 8 bits arrived incf UART_State,F ; Stay in RX data state until all bits received goto ISR_Exit ISR_TMR0_Exit: ; ; Interrupt On Change ISR ; This is a bit banged UART receive start bit ISR_IOC: btfsc INTCON,RABIE btfss INTCON,RABIF goto ISR_IOC_Exit movf PORTA,W ; Clear miss match bcf INTCON,RABIF ; Clear IOC assert btfsc RXD_BIT ; Skip when RXD is a Start Bit (LOW) goto ISR_Exit movlw T0_RELOAD+30 ; Instruction cycles overhead for RX start bit dection movwf TMR0 bcf INTCON,T0IF bsf INTCON,T0IE movlw 0x80 ; Set to receive 8 bits of RX data movwf RX_Data movlw RX_START+1 ; Set UART to receive data bits state movwf UART_State bcf INTCON,RABIE ; Disable IOC, RX start bit interrupt goto ISR_Exit ISR_IOC_Exit: ; ; Handle ADC interrupt ; ISR_ADC: banksel PIE1 ; Bank 1 btfss PIE1,ADIE ; must be enabled to wake from sleep goto ISR_ADC_Exit banksel PIR1 ; Bank 0 btfss PIR1,ADIF ; must be enabled to wake from sleep goto ISR_ADC_Exit bcf PIR1,ADIF btfss ADC_Sample bsf ADC_Sample goto ISR_Exit ISR_ADC_Exit: ISR_Exit: movf PCLATH_SAVE,W movwf PCLATH movf STATUS_SAVE,W movwf STATUS swapf WREG_SAVE,F swapf WREG_SAVE,W retfie ; ; PutC ; put a character out serial port ; Putc: btfsc INTCON,T0IE ; skip when UART not busy goto Putc bcf INTCON,RABIE ; cannot receive when sending bsf PORTC,0 ; Turn DS1 on banksel TX_Data movwf TX_Data movlw TX_START+1 ; select UART start send state movwf UART_State banksel TMR0 ; Bank 0 movlw T0_RELOAD movwf TMR0 bcf INTCON,T0IF bsf INTCON,T0IE return ; ; Wait for UART transmit to complete ; WaitForSend: btfsc INTCON,T0IE ; skip when UART not busy goto WaitForSend bcf PORTC,0 ; Turn DS1 off. return ; ; Put HEX nibble ; PutHexNibble: andlw 0x0F addlw 6 btfsc STATUS,DC addlw 'A'-'0'-10 addlw '0'-6 goto Putc PUTS_DATA UDATA_SHR prString res 2 RPUTS_CODE CODE ; ; Print an ASCII zero terminated string from CODE space ; rPuts: movf prString+1,W iorwf prString,W skpnz return call rPutsGetChar iorlw 0 skpnz return call Putc incf prString,F skpnz incf prString+1,F goto rPuts ; ; Fetch a character from CODE space ; rPutsGetChar: movf prString+1,W movwf PCLATH movf prString,W movwf PCL ; ; Main application data ; MAIN_DATA UDATA ; ; ADC data ADC_Value res 2 ; ; Process ADC delay ADC_Delay res 2 ; ; ; MAIN_CODE CODE ; ; Do a very simple command processor ; ProcessCharacter: bcf RX_DataAvailable movlw 'A' ; see if it is a toggle ADC display request xorwf RX_Data,W skpnz call ToggleAdcDisplay movlw '1' ; see if it is a select ADC channel 2 xorwf RX_Data,W movlw 0x89 ; Select AN2 as ADC input skpnz call SetADC_Channel movlw '2' ; see if it is a select ADC channel 10 xorwf RX_Data,W movlw 0xA9 ; Select AN10 as ADC input skpnz call SetADC_Channel movlw '3' ; see if it is a select ADC channel 11 xorwf RX_Data,W movlw 0xAD ; Select AN11 as ADC input skpnz call SetADC_Channel ; ; Enable RX start bit detect ; EnableStartBitDetect: banksel PORTA movf PORTA,W bcf INTCON,RABIF bsf INTCON,RABIE return ; ; Select ADC channel ; SetADC_Channel: banksel PIE1 ; Bank 1 bcf PIE1,ADIE ; disable ADC interrupt for channel change banksel ADCON0 ; Bank 0 movwf ADCON0 banksel PIE1 ; Bank 1 bsf PIE1,ADIE ; enable ADC interrupt banksel 0 ; Bank 0 return ; ; Turn the ADC display on or off ; ToggleAdcDisplay: clrc btfss ADC_Show_Sample setc skpc bcf ADC_Show_Sample skpnc bsf ADC_Show_Sample return ; ; Process ADC sample ; ProcessAdcSample: banksel ADCON0 btfsc ADCON0,GO ; Skip if ADC conversion is complete return ; ; Delay between ADC outputs because ; if we send too fast the UART receiver ; gets no cycles to detect a start bit. ; banksel ADC_Delay movf ADC_Delay,W iorwf ADC_Delay+1,W skpnz goto DisplayAdcSample decf ADC_Delay,F skpnz decf ADC_Delay+1,F return DisplayAdcSample: ; ; Reload delay count ; movlw LOW(ADC_DELAY_COUNT) movwf ADC_Delay movlw HIGH(ADC_DELAY_COUNT) movwf ADC_Delay+1 ; ; Read all 10-bits of the ADC ; banksel ADRESL movf ADRESL,W banksel ADC_Value movwf ADC_Value banksel ADRESH movf ADRESH,W banksel ADC_Value movwf ADC_Value+1 bcf ADC_Sample ; Clear process flag for ADC btfss ADC_Show_Sample return call ShowAdc ; Display ADC value call EnableStartBitDetect return ; ; Display ADC value ; ShowAdc: swapf ADC_Value+1,W call PutHexNibble movf ADC_Value+1,W call PutHexNibble swapf ADC_Value,W call PutHexNibble movf ADC_Value,W call PutHexNibble movlw 0x0D call Putc movlw 0x0A call Putc call WaitForSend return ; ; Power On Reset starts here ; start: ; ; Set internal oscillator to 8 MHz ; banksel OSCCON movlw 0x70 movwf OSCCON ; Set internal oscillator to 8MHz banksel INTCON ; Bank 0 clrf INTCON ; Disable interrupts ; ; Set all outputs to zero ; movlw 0x01 movwf PORTA ; Set TXD high clrf PORTB clrf PORTC banksel ANSEL ; Bank 2 clrf ANSEL bsf ANSEL,2 ; Assign AN2(RA2) to ADC clrf ANSELH bsf ANSELH,3 ; Assign AN10(RB4) to ADC bsf ANSELH,4 ; Assign AN11(RB5) to ADC clrf WPUB ; Disable PORTB pull-ups clrf IOCB ; Mask Interrupt On Change bits of PORTB banksel OPTION_REG ; Bank1 movlw 0x5F ; Set OPTION register movwf OPTION_REG ; TIMER0 clocks source is FCYC clrf PIE1 ; Clear all peripheral clrf PIE2 ; interrupt enables. clrf WPUA ; Disable PORTA pull-ups clrf IOCA ; Mask Interrupt On Change bits of PORTA bsf WPUA,1 ; Enable pull up on RXD (RA1) bsf IOCA,1 ; Enable interrupt on change of RXD (RA1) ; ; Set all GPIOs directions, unused are outputs ; movlw 0x06 ; Set RA1, RA2 as input movwf TRISA movlw 0x30 ; Set RB4, RB5 as input movwf TRISB movlw 0x00 movwf TRISC ; ; Initialize UART state ; banksel UART_State bcf INTCON,T0IE clrf UART_State ; ; Initialize application status flags ; clrf App_Status ; ; Setup ADC ; movlw 0x70 ; We will be asleep for the ADC conversion banksel ADCON1 ; Bank 1 movwf ADCON1 bsf PIE1,ADIE ; must be enabled to wake from sleep movlw 0x89 ; Select AN2 as ADC input banksel ADCON0 ; Bank 0 movwf ADCON0 bcf PIR1,ADIF bsf INTCON,PEIE ; ; We wake from sleep because the ADC ; interrupt request is asserted. ; bsf PORTC,0 ; Start with LED ON bsf INTCON,GIE ; ; Show the ADC value by default ; bsf ADC_Show_Sample ; ; Print the power on message ; movlw LOW(PowerOnMessage) movwf prString movlw HIGH(PowerOnMessage) movwf prString+1 call rPuts call WaitForSend ; ; Start waiting for character ; call EnableStartBitDetect ; ; This is the main process loop ; ProcessLoop: ; ; Check process flags and sleep when idle ; btfsc INTCON,T0IE goto ProcessAwake ; do not sleep when UART is running btfsc RX_DataAvailable goto ProcessAwake ; do not sleep when UART RX data is available btfsc ADC_Sample goto ProcessAwake ; do not sleep when ADC is sampling bsf ADCON0,GO ; start an ADC conversion sleep ; sleep and wait for an interrupt nop nop ; ; Process loop is awake ; ProcessAwake: btfsc RX_DataAvailable call ProcessCharacter btfsc ADC_Sample call ProcessAdcSample goto ProcessLoop PowerOnMessage: dt "PIC16F677 Analog input demo",13,10 dt "Samples ADC inputs AN2, AN10, AN11",13,10 dt "Type:"13,10 dt " 'A' to toggle ADC value display ON/OFF",13,10 dt " '1' to select AN2",13,10 dt " '2' to select AN10",13,10 dt " '3' to select AN11",13,10 dt 0 end It is possible to modify this code to use just one GPIO pin. If you can understand how this code works you should be able to make the appropriate changes. |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
779浏览 1评论
672浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
598浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
680浏览 0评论
578浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 13:13 , Processed in 1.321759 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号