here is an "exemplar" code you may glean some use of, it is for a pic16f690 demo board
The code listed above has lots of unimportant stuff in it as I use it to test snippits the important part is portc = ~~Pattern 'turn portb.0 on or off based on whether the bit is 0 or 1Code:@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BOR_OFF & _FCMEN_OFF & _IESO_OFF DEFINE OSC 4 I VAR BYTE LED var byte TEMP var WORD OVERFLOW VAR WORD Relays VAR BYTE : Relays = 0 'DEFINE ADC_BITS 10 ' Set A/D for 8-bit operation 'DEFINE ADC_CLOCK 3 ' Set A/D clock Fosc/8 'DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS temp = 0 OVERFLOW = 0 serout porta.0,2, [$FE,1,"Loops ",# temp," "] ADCON1 = 0 ANSEL = 0 portc = %00000000 TRISC = %00000000 ;LOW portB.7 ;MyPort var byte main: 'ADCIN 0, TEMP myPort var bit[8] Portc.0 = MyPort[0] Portc.1 = myPort[1] Portc.2 = myPort[2] Portc.3 = myPort[3] Porta.1 = myPort[4] Porta.2 = myPort[5] Porta.3 = myPort[6] PortB.7 = myPort[7] 'random temp 'myPort = %00000000 TrisA = %00000000 TrisB = %00000000 Trisc = %00000000 'FOR led = 0 to 4 + 1 pattern var byte index var byte 'Pattern = %11111111 'Pattern = %00001111 FOR index = 0 to 19 ;MYpORT = MYpORT + 1 LOOKUP index,[%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000101,%11111010,%00000101,%11111010,%00001001,%00000110,%11111111,%11111001,%11111111], pattern 'pattern = (pattern >>1) portc = ~~Pattern 'turn portb.0 on or off based on whether the bit is 0 or 1 ;Portc.0 = MyPort[0] ;Portc.1 = myPort[1] ;Portc.2 = myPort[2] ;Portc.3 = myPort[3] ;Porta.1 = myPort[4] ;Porta.2 = myPort[5] ;Porta.3 = myPort[6] ;PortB.7 = myPort[7] ;2 bitwise NOTS 1st not changes T/F to Pattern and second inverts value ;PORTC = Pattern is a T/F statement the ( ! ) changes it to ENGLISH :D PAUSE 300 NEXT index temp = temp + 1 serout porta.0,2, ["Loop ",# temp," "] IF TEMP >= 65535 THEN OVERFLOW = OVERFLOW + 1 IF OVERFLOW >=1 THEN SEROUT PORTA.0,2,["OVERFLOW ",#OVERFLOW," "] PAUSE 5000 ENDIF 'TEMP = TEMP / 5 'pause temp MAX 2 'portc = portc << 1 'TRISC = I 'next led 'FOR led = 0 to 3 + 1 'pause temp 'portc = portc >> 1 'next led goto main end




Bookmarks