Ir ao conteúdo
  • Cadastre-se

Recommended Posts

olá amigos! A linguagem é Basic o compilador é o picbasic pro, esse codigo é p/  placa pll fm,o problema é o seguinte a frequencia escolhida no pic ,nao sintetiza com o saa1057,por favor alguem sabe dizer onde esta o erro. o codigo completo é esse:

 

'****************************************************************
'*  compiler picbasic pro  compiler
'*  Name    : PIC16F876A - SAA1057.BAS                                                       
'*  Author  : [JCVB - CMC]                                                             
'*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS]                
'*          : All Rights Reserved                                                      
'*  Date    : 15/09/2012                                                               
'*  Version : 5.0                                                                      
'*  Notes   :                                                                           
'*          :                                                                         
'****************************************************************
 '* DEVICE PIC16F876A, PROTECT_ON
 
 'CMCON =7
 'CVRCON =0
INCLUDE "modedefs.bas"
DEFINE OSC 4            'Cristal de 8 MHz
DEFINE SHIFT_PAUSEUS 10
OPTION_REG.7 = 0        'Activamos resistencias pull-up de PortB
'DEFINE I2C_INTERNO 1 'Use p/ EEPROM interna em 16CExxx e 12CExxx
'DEFINE I2C_LENTO 1 'Use p/ OSC >8mHz c/ dispositivos de veloc. padrão
DEFINE ADC_BITS 10             ' Numero de bits
DEFINE ADC_CLOCK 3             ' Pulso de reloj (3=rc)
DEFINE ADC_SAMPLEUS 50      ' Tiempo antes del muestreo en uS
ADCON1 = %10000011          ' Conversor AD, justificación derecha, referencia RA3
                                    ' todo el puerto analógico a excepción de RA5
DEFINE LCD_BITS 4               'LCD en modo 4bits
DEFINE LCD_DREG PORTB      'Los 4 bits conectados al PORTB
DEFINE LCD_DBIST 0           'Parte baja del PORTB (RB0,RB1,RB2,RB3)
DEFINE LCD_EREG PORTB      'Enabled conectado al PORTC
DEFINE LCD_EBIT 6           'Enabled conectado a RC6
DEFINE LCD_RSREG PORTB    'RS conectado al PORTC
DEFINE LCD_RSBIT 5          'RS conectado a RC5
TRISA = %11111111
TRISB = %10010000   '11110000    888888888888888888888888888888888888888888888888888888
TRISC = %01110000  '00010000 TROCADO C5 POR B5 E C6 PORB6    88888888888888888888888888
PORTB = 0
PORTC = 0
MONITOR VAR BIT
INDICE VAR BYTE
CHAR1 VAR BYTE
CHAR2 VAR BYTE
CHAR3 VAR BYTE
CHAR4 VAR BYTE
CHAR5 VAR BYTE
CHAR6 VAR BYTE
CHAR7 VAR BYTE
CHAR8 VAR BYTE
CHAR9 VAR BYTE
CHAR10 VAR BYTE
CHAR11 VAR BYTE
CHAR12 VAR BYTE
CHAR13 VAR BYTE
CHAR14 VAR BYTE
CHAR15 VAR BYTE
CHAR16 VAR BYTE
Voltaje VAR WORD
Temperatura VAR WORD
Directa VAR WORD
Reflejada VAR WORD
Temp32 VAR WORD
frecuencia VAR WORD
FrecuenciaR VAR WORD
ultimafrec VAR WORD
config1057 VAR WORD
tiempo VAR BYTE
frech VAR BYTE
frecl VAR BYTE
I VAR BYTE
Up VAR portb.4
Down VAR portc.5  'era b5 88888888888888888888888888888888888888888888888888888888888
Menu VAR portc.6   'erab6888888888888888888888888888888888888888888888888888888888888
Program VAR portb.7
lock VAR portc.4
clb VAR portc.2
dlen VAR portc.1
dataa VAR portc.0
potencia VAR portc.3
 
config1057 = %1101110110010101  'WORDB
'Detalle de WordB
'0101    'Control de salida del pin 18 (Test point)
            '0000=1; 0001= contador programable; 0100=Frec. Ref.; 0101=Salida Lock/Unlock
'1          BRM control del bus  1 = sw automatico;  0 = siempre en ON
'00         PDM Detector de fase digital 0X = on/off automático; 10 = on; 11 = off
'1          SLA Modo del Latch A  1 = síncrono; 0 = asíncrono
'1          SB2 Habilita/deshabilita los últimos 8 bits de wordB 1 = habilita; 0 = deshabilita.
            '(Desde SLA hasta T0) Si es 0, los últimos 8 bits son colocados en 00000000
'1110       Ganancia de corriente para el voltaje de error 0000=0.023; 0001=0.07; 0010=0.23; 0110=0.7; 1110=2,3
'0          Frec. referencia 0 = 1Khz; 1 = 1.25Khz
'1          Selector FM/AM 1 = FM; 0 = AM
WRITE eeprom 0, [232,3,0,$20,$20,$20,$54,$45,$53,$49,$53,$20,$46,$49,$4D,$45,$20,$20,$20] 'Programa la EEPROM   3,232 = 1000 = 100.0 Mhz
READ 0, frecl                   'Lee
READ 1, frech                   'la EEPROM
READ 2, MONITOR
frecuencia = frech*256+frecl      'Une los bytes h y l
ultimafrec = frecuencia
LOW dLen
Pause 100                       'Espera a que el LCD inicialize
   LCDOUT $FE, 1                    'Limpia pantalla
   LCDOUT $FE, 2                    'Cursor en la 1ra línea
   LCDOUT "   Tesis  PLL"           'Muestra texto en el LCD
   LCDOUT $FE, $C0                  'Va a la 2da línea
   LCDOUT "JCVB - CMC  2011"
PAUSE 1000                           'Espera 1 Seg
'CONFIG:                  'configura el SAA1057
   dlen = 1
   SHIFTOUT dataa, clb, 1, [CONFIG1057 \16]
   dlen = 0
   dataa = 0
   PAUSEUS 5
   clb = 1
   PAUSEUS 10
   clb = 0
   pause 1

GOSUB registro      'establece frecuencia en el SAA1057
' Espera 5 segundos antes de empezar
'***************************************************
INICIO:
LCDOUT $FE, 1                        'Limpia pantalla
LCDOUT $FE, 2                       'Primera linea
LCDOUT "Locking..."                'Muestra texto en el LCD
FOR tiempo=5 TO 1 STEP -1
   LCDOUT $FE, $C0                      'Va a la 2da línea
   LCDOUT DEC tiempo, " segundos"
   PAUSE 1000                               ' Espera 500 mS
NEXT tiempo
potencia = 1
REINICIO:
GOSUB pll                        'escribe la frecuencia en el LCD
READ 3, CHAR1
READ 4, CHAR2
READ 5, CHAR3
READ 6, CHAR4
READ 7, CHAR5
READ 8, CHAR6
READ 9, CHAR7
READ 10, CHAR8
READ 11, CHAR9
READ 12, CHAR10
READ 13, CHAR11
READ 14, CHAR12
READ 15, CHAR13
READ 16, CHAR14
READ 17, CHAR15
READ 18, CHAR16
LCDOUT $FE, $C0                      ' 2da línea
LCDOUT CHAR1, char2, char3, char4, char5, char6, char7, char8, char9, char10, char11, char12, char13, char14, char15, char16
PAUSE 100         

'***************************************************
'Programa Principal
operando:
    IF  Menu = 0 THEN
        PAUSE 5000
        IF menu = 0 THEN
            PAUSE 100
            LCDOUT $FE, 1
            LCDOUT "Load..."
            LCDOUT $FE, $C0                      ' 2da línea
            LCDOUT "Nombre  Estacion"                  ' 2da línea
            PAUSE 3000
            indice = 1
            LCDOUT $FE, 1
            LCDOUT     char1, char2, char3, char4, char5, char6, char7, char8, char9, char10, char11, char12, char13, char14, char15, char16
            LCDOUT $FE, 2
            LCDOUT $FE, $0E
            GOTO cambia_nombre
        ENDIF
    ENDIF
    
    IF Program = 0 THEN
        PAUSE 5000
        IF program = 0 THEN
            PAUSE 100
            LCDOUT $FE, 1
            LCDOUT "Load..."
            LCDOUT $FE, $C0                      ' 2da línea
            LCDOUT "Prog. Frecuencia"              ' 2da línea            
            PAUSE 3000
            GOTO cambia_frecuencia
        ENDIF
    ENDIF
    IF Down = 0 THEN
        PAUSE 5000
        IF Down = 0 THEN
            pause 100
            LCDOUT $FE, 1
            LCDOUT "Load..."
            LCDOUT $FE, $C0                      '2da línea
            LCDOUT "Hardware Monitor"            '2da línea
            PAUSE 3000
            GOTO HARDWARE_MONITOR
        ENDIF
    ENDIF
    IF Up = 0 THEN
        PAUSE 5000
        IF Up = 0 THEN
            PAUSE 100
            LCDOUT $FE, 1
            LCDOUT "Load..."
            LCDOUT $FE, $C0                      '2da línea
            LCDOUT " Config Monitor"            '2da línea
            PAUSE 3000
            IF MONITOR = 1 THEN
                LCDOUT $FE, 1
                LCDOUT $FE, $C0                      '2da línea
                LCDOUT "   Monitor ON"
            ELSE
                LCDOUT $FE, 1
                LCDOUT $FE, $C0                      '2da línea
                LCDOUT "  Monitor  OFF"
            ENDIF
            GOTO CONFIG_MONITOR
        ENDIF
    ENDIF
    
    IF lock = 0 THEN
        LCDOUT $FE, 2, "Unlock"
        potencia = 0
    ELSE
        LCDOUT $FE, 2, "Lock  "
        potencia = 1
    ENDIF
    
    IF MONITOR = 1 THEN
        GOSUB SENSORES
        IF Reflejada > 5 OR Temperatura > 50 OR voltaje > 500 THEN
            GOTO PROTECCION
        ENDIF
    ENDIF
    
    PAUSE 1
GOTO operando
'Escribe registro
registro:
   FrecuenciaR = frecuencia  * 10
   dlen = 1
   SHIFTOUT dataa, clb, 1, [FrecuenciaR\16]
   dlen = 0
   dataa = 0
   PAUSEUS 5
   clb = 1
   PAUSEUS 10
   clb = 0
   pause 1
RETURN
'fin escribe registro
'***************************************************
'Rutina del PLL. Escribe frecuencia en el SAA1057
PLL:
    frecl = frecuencia
    frech = (frecuencia-frecl)/256      '888888888888888888888888888888888888888   8888
    
    IF ultimafrec <> frecuencia THEN     'Graba solo cuando hay cambio
        WRITE 0, frecl              'Graba eeprom
        WRITE 1, frech              'Graba eeprom
    ENDIF
    GOSUB registro
    IF frecuencia < 1000 THEN  '<108  88888888888888888888888888888               erro
        LCDOUT $FE, 1               'Limpia LCD
        LCDOUT "         ", DEC (frecuencia/10), ".", DEC1 frecuencia, "Mhz"
    ELSE
        LCDOUT $FE, 1               'Limpia LCD
        LCDOUT "        ", DEC (frecuencia/10), ".", DEC1 frecuencia, "Mhz"
    ENDIF
RETURN

'***********************************************
'Rutina cambio de nombre a la Estación
CAMBIA_NOMBRE:
    IF up = 0 THEN
        PAUSE 100
        SELECT CASE INDICE
            CASE 1: char1 = char1 + $01: IF char1 = $80 THEN: char1 = $7F
                    LCDOUT char1: LCDOUT $FE, $10
            CASE 2: char2 = char2 + $01: IF CHAR2 = $80 THEN: CHAR2 = $7F
                    LCDOUT char2: LCDOUT $FE, $10
            CASE 3: char3 = char3 + $01: IF CHAR3 = $80 THEN: CHAR3 = $7F
                    LCDOUT char3: LCDOUT $FE, $10
            CASE 4: char4 = char4 + $01: IF CHAR4 = $80 THEN: CHAR4 = $7F
                    LCDOUT char4: LCDOUT $FE, $10
            CASE 5: char5 = char5 + $01: IF CHAR5 = $80 THEN: CHAR5 = $7F
                    LCDOUT char5: LCDOUT $FE, $10
            CASE 6: char6 = char6 + $01: IF CHAR6 = $80 THEN: CHAR6 = $7F
                    LCDOUT char6: LCDOUT $FE, $10
            CASE 7: char7 = char7 + $01: IF CHAR7 = $80 THEN: CHAR7 = $7F
                    LCDOUT char7: LCDOUT $FE, $10
            CASE 8: char8 = char8 + $01: IF CHAR8 = $80 THEN: CHAR8 = $7F
                    LCDOUT char8: LCDOUT $FE, $10
            CASE 9: char9 = char9 + $01: IF CHAR9 = $80 THEN: CHAR9 = $7F
                    LCDOUT char9: LCDOUT $FE, $10
            CASE 10: char10 = char10 + $01: IF CHAR10 = $80 THEN: CHAR10 = $7F
                     LCDOUT char10: LCDOUT $FE, $10
            CASE 11: char11 = char11 + $01: IF CHAR11 = $80 THEN: CHAR11 = $7F
                     LCDOUT char11: LCDOUT $FE, $10
            CASE 12: char12 = char12 + $01: IF CHAR12 = $80 THEN: CHAR12 = $7F
                     LCDOUT char12: LCDOUT $FE, $10
            CASE 13: char13 = char13 + $01: IF CHAR13 = $80 THEN: CHAR13 = $7F
                     LCDOUT char13: LCDOUT $FE, $10
            CASE 14: char14 = char14 + $01: IF CHAR14 = $80 THEN: CHAR14 = $7F
                     LCDOUT char14: LCDOUT $FE, $10
            CASE 15: char15 = char15 + $01: IF CHAR15 = $80 THEN: CHAR15 = $7F
                     LCDOUT char15: LCDOUT $FE, $10
            CASE 16: char16 = char16 + $01: IF CHAR16 = $80 THEN: CHAR16 = $7F
                     LCDOUT char16: LCDOUT $FE, $10
        END SELECT        
    ENDIF
    IF Down = 0 THEN
        PAUSE 100
        SELECT CASE indice
            CASE 1: CHAR1 = CHAR1 - $01: IF CHAR1 = $1F THEN: CHAR1 = $20
                    LCDOUT char1: LCDOUT $FE, $10
            CASE 2: char2 = char2 - $01: IF CHAR2 = $1F THEN: CHAR2 = $20
                    LCDOUT char2: LCDOUT $FE, $10
            CASE 3: char3 = char3 - $01: IF CHAR3 = $1F THEN: CHAR3 = $20
                    LCDOUT char3: LCDOUT $FE, $10
            CASE 4: char4 = char4 - $01: IF CHAR4 = $1F THEN: CHAR4 = $20
                    LCDOUT char4: LCDOUT $FE, $10
            CASE 5: char5 = char5 - $01: IF CHAR5 = $1F THEN: CHAR5 = $20
                    LCDOUT char5: LCDOUT $FE, $10
            CASE 6: char6 = char6 - $01: IF CHAR6 = $1F THEN: CHAR6 = $20
                    LCDOUT char6: LCDOUT $FE, $10
            CASE 7: char7 = char7 - $01: IF CHAR7 = $1F THEN: CHAR7 = $20
                    LCDOUT char7: LCDOUT $FE, $10
            CASE 8: char8 = char8 - $01: IF CHAR8 = $1F THEN: CHAR8 = $20
                    LCDOUT char8: LCDOUT $FE, $10
            CASE 9: char9 = char9 - $01: IF CHAR9 = $1F THEN: CHAR9 = $20
                    LCDOUT char9: LCDOUT $FE, $10
            CASE 10: char10 = char10 - $01: IF CHAR10 = $1F THEN: CHAR10 = $20
                     LCDOUT char10: LCDOUT $FE, $10
            CASE 11: char11 = char11 - $01: IF CHAR11 = $1F THEN: CHAR11 = $20
                     LCDOUT char11: LCDOUT $FE, $10
            CASE 12: char12 = char12 - $01: IF CHAR12 = $1F THEN: CHAR12 = $20
                     LCDOUT char12: LCDOUT $FE, $10
            CASE 13: char13 = char13 - $01: IF CHAR13 = $1F THEN: CHAR13 = $20
                     LCDOUT char13: LCDOUT $FE, $10
            CASE 14: char14 = char14 - $01: IF CHAR14 = $1F THEN: CHAR14 = $20
                     LCDOUT char14: LCDOUT $FE, $10
            CASE 15: char15 = char15 - $01: IF CHAR15 = $1F THEN: CHAR15 = $20
                     LCDOUT char15: LCDOUT $FE, $10
            CASE 16: char16 = char16 - $01: IF CHAR16 = $1F THEN: CHAR16 = $20
                     LCDOUT char16: LCDOUT $FE, $10
        END SELECT        
    ENDIF
    PAUSE 100
    IF Menu = 0 THEN
        PAUSE 100
        indice = indice + 1
        IF INDICE = 17 THEN
            INDICE = 1
            LCDOUT $FE, $2
        ELSE
            LCDOUT $FE, $14
        ENDIF
        
    ENDIF
    IF program = 0 THEN
        PAUSE 100
        LCDOUT $FE, $C0
        WRITE 3, CHAR1
        WRITE 4, CHAR2
        WRITE 5, CHAR3
        WRITE 6, CHAR4
        WRITE 7, CHAR5
        WRITE 8, CHAR6
        WRITE 9, CHAR7
        WRITE 10, CHAR8
        WRITE 11, CHAR9
        WRITE 12, CHAR10
        WRITE 13, CHAR11
        WRITE 14, CHAR12
        WRITE 15, CHAR13
        WRITE 16, CHAR14
        WRITE 17, CHAR15
        WRITE 18, CHAR16        
        LCDOUT $FE, 1                        'Limpia pantalla
        LCDOUT "  Guardando..."            'Muestra texto en el LCD
        LCDOUT $FE, $0C
        PAUSE 2000
        GOTO REINICIO
    ENDIF
 GOTO CAMBIA_NOMBRE
'********************************************
'Cambio de Frecuencia
CAMBIA_FRECUENCIA:
    GOSUB pll
    LCDOUT $FE, $C0    
    LCDOUT "Prog. Frecuencia"    
FOR I=1 TO 200
    IF up=0 THEN
        PAUSE 200
        frecuencia = frecuencia + 1
        IF frecuencia < 1081 THEN   
            ELSE
            frecuencia = 1080
        ENDIF
    ENDIF
    
    IF down = 0 THEN
        PAUSE 200
        frecuencia = frecuencia-1
        IF frecuencia > 874 THEN    
            ELSE
            frecuencia = 875    
        ENDIF
    ENDIF
    IF Program = 0 THEN    
        PAUSE 100
        GOSUB registro
        LCDOUT $fe, 1
        LCDOUT $fe, 2
        LCDOUT "       OK"
        PAUSE 3000
        GOSUB pll  
        LCDOUT $FE, $C0              ' 2da línea
        LCDOUT       char1, char2, char3, char4, char5, char6, char7, char8, char9, char10, char11, char12, char13, char14, char15, char16
        PAUSE 100
        GOTO operando
    ENDIF
    PAUSE 1
NEXT I
    
GOTO CAMBIA_FRECUENCIA
'***********************************
'Monitor de Hardware
HARDWARE_MONITOR:
    GOSUB sensores
    LCDOUT $FE, 1
    LCDOUT $FE, 2
    LCDOUT "V:", DEC (voltaje/10), ".", DEC1 voltaje, "V", "  ", "T:", DEC temperatura, "'C"
    LCDOUT $FE, $C0
    LCDOUT "D:", DEC (Directa/10),".", DEC1 directa, "W", "  ", "R:", DEC (reflejada/10), ".", DEC1 reflejada, "W"
    FOR I=1 TO 200
        PAUSE 1
        IF program =0 THEN: PAUSE 300: GOTO reinicio
    NEXT I
GOTO HARDWARE_MONITOR

'************************************
'Adquisición de datos de los sensores
SENSORES:
    ADCIN 0, directa
    IF directa <= 255 THEN
        directa = (directa * directa)/1000
    ELSE
        directa = directa * directa
        Temp32 = DIV32 1000
        directa = Temp32
    ENDIF
    ADCIN 1, reflejada
    reflejada = (reflejada * reflejada)/1000
    ADCIN 2, voltaje
    ADCIN 4, temperatura
    Temperatura = Temperatura/10
RETURN
'****************************************************
'Configuración del Monitor de Hardware
CONFIG_MONITOR:
    IF up = 0 THEN
        PAUSE 100
        IF MONITOR = 0 THEN
            MONITOR = 1
            LCDOUT $FE, 1
            LCDOUT $FE, $C0                  ' 2da línea
            LCDOUT "   Monitor ON"
        ENDIF
    ENDIF
    IF Down = 0 THEN
        PAUSE 100
        IF monitor = 1 THEN
            monitor = 0
            LCDOUT $FE, 1
            LCDOUT $FE, $C0                  ' 2da línea
            LCDOUT "  Monitor  OFF"
        ENDIF
    ENDIF
    IF Program = 0 THEN
        PAUSE 100
        LCDOUT $FE, 1
        LCDOUT $FE, 2                      ' 2da línea
        LCDOUT "Guardando..."
        PAUSE 1000
        WRITE 2, MONITOR
        GOTO REINICIO
    ENDIF
    IF Menu = 0 THEN
        PAUSE 100
        LCDOUT $FE, 1
        LCDOUT $FE, 2                      '2da línea
        LCDOUT "Cancelando..."
        PAUSE 1000
        GOTO reinicio            
    ENDIF
    
    PAUSE 10        
         
GOTO CONFIG_MONITOR

'****************************************************
'Bloqueo del sistema
PROTECCION:
   PORTC.7 = 1
   LCDOUT $FE, 1                        'Limpia pantalla
   LCDOUT $FE, 2                        'Cursor en la 1ra línea
   LCDOUT "     ERROR"               'Muestra texto en el LCD
    IF Reflejada > 5 THEN
        LCDOUT $FE, $C0                  'Va a la 2da línea
        LCDOUT "Pot.Ref. Elevada"
    ENDIF
    IF Temperatura > 50 THEN
        LCDOUT $FE, $C0                  'Va a la 2da línea
        LCDOUT "Tempera. Elevada"
    ENDIF
    IF voltaje > 500 THEN
        LCDOUT $FE, $C0                  'Va a la 2da línea
        LCDOUT "Voltaje  Elevado"
    ENDIF
    BLOQUEO:
        PAUSE 1000
    GOTO BLOQUEO
END

 

Editado por DiF
Ao postar um código, use sempre o botão CODE <>

Compartilhar este post


Link para o post
Compartilhar em outros sites

@nasciment ,

 

Vai ser difícil. Nunca ví alguém aqui no Fórum programar com esse compilador. Mas espere mais um pouco, quem sabe aparece algum usuário que fica na moita !

 

Paulo

  • Curtir 2

Compartilhar este post


Link para o post
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora





Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas publicações sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×